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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.