December 2018
Intermediate to advanced
414 pages
10h 19m
English
A raw type is a base type for all enumeration members; in our example, we can hardcode presets for our dimming, as follows:
enum LightLevel: String { case quarter case half case threequarters}let state: State<LightLevel> = .dimmed(.half)
Thanks to the generic implementation and the fact that String is equatable, we can use this raw value in our dimmed state.
With the LightLevel enum, which has a raw type of String, the compiler will use the member name as the underlying raw value:
LightLevel.half.rawValue == “half” // == true
You can override these by specifying them, as follows:
enum LightLevel: String { case quarter = “1/4” case half = “1/2” case threequarters = “3/4”}
When using Int as a raw type, the underlying raw values ...
Read now
Unlock full access