我有一个在后台线程中使用self
的代码。它运行得非常好,直到我将它迁移到Swift 3,从那时起我每次使用self
时都会得到一条错误消息:&#34; Closure不能隐式捕获变异的自身参数&#34;。< / p>
我的代码是这样的:
mutating func fetchData() {
DispatchQueue.global(qos: .background).async {
for className in self.classNames {
let query = PFQuery(className: className)
query.limit = 1000
do {
for obj in try query.findObjects() {
let typeObj = TypeObj(parseObject: obj, typeName: className)
if className == “type1”{
self.type1s.append(store)
} else if className == “type2” {
self.type2s.append(store)
} else if className == “type3” {
self.type3s.append(store)
} else if className == “type4” {
self.type4s.append(store)
} else if className == “type5” {
self.type5s.append(store)
}
}
}
catch _ {
// Error handling
}
}
let dict = [
“Type1s”:self.type1s,”Type2s”:self.type2s,”Type3s”:self.type3s,”Type4s”:self.type4s,”Type5s”:self.type5s
]
self.delegate.getDictionary(dict)
}
}