Swift: Enumerations

Enumeration defines a common type for a group of related values that allows as to work with those values in a type safe manner. We introduce enumeration with ‘enum‘ keyword. The entire enumeration must be contained with the braces {}. We introduce individual cases using ‘case‘ keyword. Multiple cases can appear in single line separated by commas. Enumerations support few characteristics that are only available to Classes such as:

  • Conformance to protocols
  • Computed properties
  • instance methods
  • initializers
  • extensions

Enumerations are like new Swift types, they have to be named following upperCamelCase format.

 

Leave a Reply