我有一个变量,我希望在闭包内更新并在其外部访问。但是,我正努力将数据从关闭中解脱出来。我之前已经做好了,但忘记了我是怎么做到的。
这是我的代码:
let query = PFUser.query()
query?.whereKey("phoneNumber", containedIn: myContactsPhoneNumbers as [AnyObject])
query?.findObjectsInBackgroundWithBlock({ (objects, error) -> Void in
for existingUser in objects! {
self.contactsOnApp.append(existingUser)
}
})
答案 0 :(得分:0)
//write one function to use upadated values , call the function from closure.
let query = PFUser.query()
query?.whereKey("phoneNumber", containedIn: myContactsPhoneNumbers as [AnyObject])
query?.findObjectsInBackgroundWithBlock({ (objects, error) -> Void in
for existingUser in objects! {
self.contactsOnApp.append(existingUser)
}
self.functionToUseUpadatedData(self.contactsOnApp)
})
func functionToUseUpadatedData(data: AnyObject) {
NSLog("implementation write here")
}