I can't initialize an enumeration using the rawValue initializer. Any thoughts? Error commented below:
//: Playground - noun: a place where people can play
// Xcode Version 7.3 (7D175)
import UIKit
enum Theme {
case Default, Dark, Graphical
}
let possibleTheme = Theme(rawValue: 1)
// Error: 'Theme' cannot be constructed because it has no accessible initializers.
enum Theme: Int {
case Default, Dark, Graphical
}
let possibleTheme = Theme(rawValue: 1) // Dark
An enum doesn't have a raw value unless you specify its type. Possible raw value types are String, Character and any of the number types. Documentation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With