viktor
viktor

Reputation: 31

Too many objects to delete in Parse, blocks UI: Doesnt respond, cancel deletion

I am trying to delete elements from Parse after filtering. Everything works fine when the number of elements is relatively small. However, when it increases, the problem arises. Basically, I am filtering among hundreds of elements stored in Parse. Among those, hundreds will have to be deleted.

Here are my codes:

       dispatch_async(dispatch_get_main_queue(), {

                                              var x2 = self.X as [NSArray]

                                            for po2 in CULA {

                                                var arr2 = po2 as! NSArray


                                                    if contains(x2, arr2) {

                                                    }
                                                    else {

                          PFUser.currentUser()!["myLocation"]?.removeObject(arr2)
                                      } } })

I am using a dispatch_async at the beginning because I want this part to be executed last and separately from the codes above as the filtering occurs. I think the removeObject function is one that blocks activity, however I dont know how to get around that. Any idea ?

Thanks a lot,

Upvotes: 0

Views: 62

Answers (2)

ABC
ABC

Reputation: 41

You are absolutely dispatching to a queue, but the main queue, which is also hte UI queue. Try putting it in a queue that will be processed by a thread that is not the main UI thread.

Here's a simple snippet that can illestrate how to dispatch for async processing off of the UI thread (and then if UI updates based on the async processing how to queue it for processing on the main UI thread)

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0 {   //take off main ui thread to prevent any blocking
    //Do work
    dispatch_async(dispatch_get_main_queue(), {//put back on to the main ui thread

    }
}

There's a whole world to understand within Grand Central Dispatch, but for your above snippet, simply queue it up to be processed off the main ui thread.

Upvotes: 0

pbush25
pbush25

Reputation: 5248

You can use the deleteInBackground method that will delete all of your objects async and not muddle up your main thread or your UI.

Upvotes: 1

Related Questions