I have to carry out a series of download and database write operations in my app. I am using the NSOperation
and NSOperationQueue
for the same.
The summary from the docs is operations are always executed on a separate thread
(post iOS 4 implies GCD underlying operation queues).
It's trivial to check that it is indeed running on a non-main thread:
NSLog(@"main thread? %@", [NSThread isMainThread] ? @"YES" : @"NO");
When running in a thread it's trivial to use GCD/libdispatch to run something on the main thread, whether core data, user interface or other code required to run on the main thread:
dispatch_async(dispatch_get_main_queue(), ^{
// this is now running on the main thread
});