Ios $T7??没有成员';发电机&x27;迅速地

Ios $T7??没有成员';发电机&x27;迅速地,ios,swift,Ios,Swift,我有一个变量名为 var items : ItemClass 我是这样初始化的 init(){ items = ItemClass() } class ItemClass{ var property : Dictionary<String, AnyObject>? init(){ self.property = Dictionary<String, AnyObject>() } } ItemClass是这样的 ini

我有一个变量名为

var items : ItemClass
我是这样初始化的

init(){
    items = ItemClass()
}
class ItemClass{
    var property : Dictionary<String, AnyObject>?

    init(){
        self.property = Dictionary<String, AnyObject>()
    }
}
ItemClass是这样的

init(){
    items = ItemClass()
}
class ItemClass{
    var property : Dictionary<String, AnyObject>?

    init(){
        self.property = Dictionary<String, AnyObject>()
    }
}

如何正确运行循环?

属性是可选的,因此它可能为零。不能在该上下文中使用可选链接。因此,您必须使用强制展开:

for k in items.property!.keys {

}
或者使用可选绑定使其更安全:

if let property = items.property {
    for k in property.keys {

    }
}

属性
是可选的,因此它可能为零。不能在该上下文中使用可选链接。因此,您必须使用强制展开:

for k in items.property!.keys {

}
或者使用可选绑定使其更安全:

if let property = items.property {
    for k in property.keys {

    }
}