I am calling the following Class method from within my ViewController init method:
[NSURLConnection sendAsynchronousRequest:urlrequest
queue:opQueue
completionHandler:^(NSURLResponse *response, NSData *data, NSError*error){
// Update an NSMutableArray (an Instance variable
[self tableView] reloadData]; // is this ok to call?
}];
This code working as intended and tableView refreshes appropriately, My concern: is this call thread safe?. is it ok to access an UI element from the completion block?
Thanks,
Vinod
It is thread safe. Very much because you are not using threads. The completion handler is just called later, not on a separate thread.
Actually, this is not correct unless opQueue happens to be +[NSOperationQueue mainQueue]
That completion block will be scheduled on the queue you provide. In your case, you're calling that queue 'opQueue'. If that queue is being drained by some thread other than the main thread, then you shouldn't make that call to reload the tableview there.
You should instead do whatever processing you need to do and then enqueue another block on the main queue which calls the reload.
Or if the processing is light and quick (and fixed amount of time), then just pass the mainQueue as the 'opQueue';
I hope that makes sense. A lot of good information to be found here: Concurrency Programming Guide