我正在尝试创建一个类,并使用该类作为我的新枚举的类型,如下所示.
class Abc{
var age = 25
var name = "Abhi"
}
enum TestEnum : Abc {
case firstCase
case secondCase
}
Run Code Online (Sandbox Code Playgroud)
我在操场上遇到以下错误.
error: raw type 'Abc' is not expressible by any literal
Run Code Online (Sandbox Code Playgroud)
所以我尝试遵循这样的RawRepresentable协议.
extension TestEnum : RawRepresentable{
typealias RawValue = Abc
init?(rawValue:RawValue ) {
switch rawValue {
case Abc.age :
self = .firstCase
case Abc.name :
self = .secondCase
}
}
var rawValue : RawValue {
switch self{
case .firstCase :
return Abc.age
case .secondCase :
return Abc.name
} …Run Code Online (Sandbox Code Playgroud) 我试图将我的plist中的一些数据加载到数组中.在声明一个数组时,我做了类似的事情
var natureList : [Dictionary] = [] as! [Dictionary]
Run Code Online (Sandbox Code Playgroud)
那么我如何声明一个数组来从我的plist加载这些数据.?我知道它很简单,但这个小东西正在吃我的脑袋.任何帮助赞赏.