| Start |
|---|
| Basic enumerations An enum (opens new window) provides a set of related values: Enum values can be used by their fully-qualified name, but you can omit the type name when it can be inferred: The most fundamental way of comparing/extracting enum values is with a Simple enums are automatically |
| Enums with associated values Enum cases can contain one or more payloads (associated values): The payload must be provided when instantiating the enum value: The A single case extraction can be done using The Enums with associated values are not |
| Indirect payloads Normally, enums can't be recursive (because they would require infinite storage): The
|
| Raw and Hash values Enums without payloads can have raw values of any literal type: Enums without any specific type do not expose the rawValue property Integer raw values are assumed to start at 0 and increase monotonically: String raw values can be synthesized automatically: A raw-valued enum automatically conforms to RawRepresentable (opens new window). You can get an enum value's corresponding raw value with You can also create an enum from a raw value using If you wish to get the hash value of a specific enum you can access its hashValue, The hash value will return the index of the enum starting from zero. |
| Initializers Enums can have custom init methods that can be more useful than the default Using that initializer we can do this: |
| Enumerations share many features with classes and structures Enums in Swift are much more powerful than some of their counterparts in other languages, such as C (opens new window). They share many features with classes (opens new window) and structs (opens new window), such as defining initialisers (opens new window), computed properties (opens new window), instance methods (opens new window), protocol conformances (opens new window) and extensions (opens new window). |
| Nested Enumerations You can nest enumerations one inside an other, this allows you to structure hierarchical enums to be more organized and clear. And you can use it like that: RemarksLike structs and unlike classes, enums are value types and are copied instead of referenced when passed around. For more information about enums, see The Swift Programming Language (opens new window). |
Read Article
https://develop.horje.com/learn/1434/reference