- An enumeration defines a common type for a group of related values and enables you to work with those values in a type-safe way within your code.
Or when a property can have its value only out of a defined set, enum is the solution which complimentary provides type-safety and auto-completion at compile time.
- Enumerations can define initializers to provide an initial case value; can be extended to expand their functionality beyond their original implementation; can have functions and can conform to protocols to provide standard functionality.
- Enums can have nested enums and associated values.
- Enums can be recursive: A recursive enumeration is an enumeration that has another instance of the enumeration as the associated value for one or more of the enumeration cases. “Indirect” keyword is used to inform the compiler about recursion.
- Each enum case’s rawValue depends upon the raw type taken and if no raw type is not taken than rawValue wouldn’t be available. Swift’s enums don’t bound to use only integer type as a raw type, you can use Strings, Characters or even Floats instead.