Enum with Raw Values in Swift

Level 279 keystrokes

Defines an enum whose cases have Int raw values and prints the raw value of .done, 1.

Swift code

// : Int after the name sets the raw value type
1enum Status: Int {
// Each case gets an explicit raw value
2 case pending = 0
3 case done = 1
4}
// rawValue returns the value assigned to the case: 1
5print(Status.done.rawValue)

Output

1
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this Swift code and how often they appear.

  • .× 2
  • =× 2
  • :× 1
  • (× 1
  • )× 1
  • {× 1
  • }× 1

More Swift examples at level 2

← Swift typing practice