Does the RESTOperation onCompletion block run on the iOS main/UI thread?

Showing 1-3 of 3 messages
Does the RESTOperation onCompletion block run on the iOS main/UI thread? Axel Niklasson 4/11/12 3:03 AM
First a big thanks to all contributors, great info source. This is my first post and I disclaim knowledge in all areas related to my question. I have googled and read the docs and I can guess the answer but would like to know for sure: Does the RESTOperation onCompletion block run on the iOS main/UI thread?

In my code I (possibly unnecessarily) make sure the UI stuff runs on the main thread, as in the below example. It's been running fine with or without the dispatch but that could just be luck. (On a side not it would also be interesting to know the "cost" of an unnecessary dispatch call. But that would just be a bonus.)

Thanks for reading,
Axel

    CouchDocument* doc = [self.database untitledDocument];
    RESTOperation* op = [doc putProperties:jsonPatient];
    [op onCompletion: ^{
        if (op.error)
            NSLog(@"Couldn't save the new item");
        else {
            NSLog(@"Item saved");
            dispatch_async(dispatch_get_main_queue(), ^{
                [self.popSegue.popoverController dismissPopoverAnimated:YES];
                [self.tableView reloadData];
            });
        }        
    }];
Re: Does the RESTOperation onCompletion block run on the iOS main/UI thread? Jens Alfke 4/11/12 10:15 AM

On Apr 11, 2012, at 3:03 AM, Axel Niklasson wrote:

Does the RESTOperation onCompletion block run on the iOS main/UI thread?

It runs on the same thread that initiated the RESTOperation. (That derives from the fact that NSURLConnection calls its delegate on the thread from which it was started.) 

So yes, if you do your work on the main thread, the onCompletion blocks run on the main thread too.

—Jens
Re: Does the RESTOperation onCompletion block run on the iOS main/UI thread? Axel Niklasson 4/13/12 6:36 AM
Great, thanks!