繁体   English   中英

枚举:“无法构造,因为它没有可访问的初始值设定项”

[英]Enumeration: “cannot be constructed because it has no accessible initializers”

我无法使用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.
enum Theme: Int {
    case Default, Dark, Graphical
}

let possibleTheme = Theme(rawValue: 1) // Dark

除非指定其类型,否则枚举没有原始值。 可能的原始值类型是StringCharacter和任何数字类型。 文档

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM