Flow control is very simple in iOS
To make something run in the background, you do the following:
- (void)someMethod { // method is called on main thread normally dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ .... // here things are run in background }); }
To return to the main thread anywhere, do the following:
- (void)someOtherMethod { // method is called on background thread dispatch_async(dispatch_get_main_queue(), ^{ ... // here things are on main thread again }); }
source share