Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A long-running operation is being executed on the main thread. Swift

In my ProfileViewController I have a query that retrieves the users profile picture which is stored as a PF File.

  var query = PFQuery(className:"Users")
    query.whereKeyExists("profilePicture")
    query.findObjectsInBackgroundWithBlock {
        (objects: [AnyObject]!, error: NSError!) -> Void in
        if error == nil {

            self.userNameLabel.text = PFUser.currentUser().username

            if let imageFile = PFUser.currentUser().objectForKey("profilePicture") as? PFFile {
                if let data = imageFile.getData() {
                    self.profPic.image = UIImage(data: data)
                }
            }

        }
        else {
            println("User has not profile picture")
        }
    }

This is the only query in this view, I have another query in my Home page of my app that has all the posts of all the user. The error I am getting i s A long-running operation is being executed on the main thread. Followed by Break on warnBlockingOperationOnMainThread() to debug.

I don't know how to work around this especially since I need to do another query to get the current users post for there profile. Should I use something other than findObjectsInBackgroundWithBlock. Thanks.

like image 820
kareem Avatar asked Feb 11 '23 06:02

kareem


1 Answers

The warning is from the Parse sdk. This part: imageFile.getData() is synchronous, and Parse is kind enough to warn you when using any of the blocking calls. There are a couple varieties of getDataInBackground... available as alternatives. See them in the docs here.

like image 80
danh Avatar answered Feb 13 '23 20:02

danh