Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 从findinbackground发送到uithread_Ios_Swift_Parse Platform - Fatal编程技术网

Ios 从findinbackground发送到uithread

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 }

我只是想知道在后台做了一些事情之后,是否有一种方法可以将一些东西发送到ui线程

 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中使用此代码。我想你能做到。我没有测试。我更改了答案以说明如何添加代码。