'self' 被 &&, || 的闭包错误捕获操作员
'self' captured by a closure error with &&, || operator
我有一个初始化方法。
为什么我看到 'self' 在所有成员初始化之前被闭包捕获 如果我使用 && 或 ||操作数.
var type:Type? = .non
init(dictionary:[String:AnyObject]){
if let type = dictionary["type"] as? Int {
self.type = Type.init(rawValue: type)!
}
//'self' captured by a closure before all members were initialized
if self.type == .picture || self.type == .textWithPicture {
//........
}
}
您是否从 NSObject 继承了 class?如果是,你需要在使用这个class的属性之前调用super的init方法。
我有一个初始化方法。 为什么我看到 'self' 在所有成员初始化之前被闭包捕获 如果我使用 && 或 ||操作数.
var type:Type? = .non
init(dictionary:[String:AnyObject]){
if let type = dictionary["type"] as? Int {
self.type = Type.init(rawValue: type)!
}
//'self' captured by a closure before all members were initialized
if self.type == .picture || self.type == .textWithPicture {
//........
}
}
您是否从 NSObject 继承了 class?如果是,你需要在使用这个class的属性之前调用super的init方法。