gpt4 book ai didi

swift - 枚举 : "cannot be constructed because it has no accessible initializers"

转载 作者:搜寻专家 更新时间:2023-10-30 21:48:29 24 4
gpt4 key购买 nike

我无法使用 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 和任何数字类型。 Documentation

关于swift - 枚举 : "cannot be constructed because it has no accessible initializers",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36185557/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com