Ios 从findinbackground发送到uithread
我只是想知道在后台做了一些事情之后,是否有一种方法可以将一些东西发送到ui线程Ios 从findinbackground发送到uithread,ios,swift,parse-platform,Ios,Swift,Parse Platform,我只是想知道在后台做了一些事情之后,是否有一种方法可以将一些东西发送到ui线程 qUserActivity.findObjectsInBackground(block: {(objects, error) in if error != nil{ print(error) }else { total = (objects?.count)! total = 1 }
qUserActivity.findObjectsInBackground(block: {(objects, error) in
if error != nil{
print(error)
}else {
total = (objects?.count)!
total = 1
}
//Update the ui thread here?
})
您可以这样做:
swift 2.2
dispatch_async(dispatch_get_main_queue(), {
//your ui code here
})
swift 3.0
DispatchQueue.main.async(execute: {
// your ui code here
})
因此,在您的代码中:
qUserActivity.findObjectsInBackground(block: {(objects, error) in
if error != nil{
print(error)
}else {
total = (objects?.count)!
total = 1
dispatch_async(dispatch_get_main_queue(), {
self.myLabel.text = "something"
})
}
})
这可以应用于parseQueries?在注释位置的parseQueries中使用此代码。我想你能做到。我没有测试。我更改了答案以说明如何添加代码。