簡體   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