我无法使用rawValue初始化程序初始化枚举.有什么想法吗?错误评论如下:
//: 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.
Run Code Online (Sandbox Code Playgroud)
Tim*_*len 24
enum Theme: Int {
case Default, Dark, Graphical
}
let possibleTheme = Theme(rawValue: 1) // Dark
Run Code Online (Sandbox Code Playgroud)
除非指定其类型,否则枚举没有原始值.可能的原始值类型是String,Character以及任何数字类型.文档
| 归档时间: |
|
| 查看次数: |
6946 次 |
| 最近记录: |