Created
April 25, 2014 17:16
-
-
Save Baekalfen/11296773 to your computer and use it in GitHub Desktop.
Running a method async, and call method on finish in Objective-C. Good for running method while updating the UI on OS X. Used some code from here: http://stackoverflow.com/questions/8854100/objective-c-async-call-a-method-using-ios-4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void) someMethod{ | |
[self dispatchBlockAsync:^{ | |
[self method1]; | |
} callOnReturn:^{ | |
[self method2];] | |
}]; | |
} | |
- (void)dispatchBlockAsync:(void(^)(void))callBlock callOnReturn:(void(^)(void))returnBlock{ | |
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); | |
dispatch_async(queue, ^ { | |
callBlock(); | |
dispatch_async(dispatch_get_main_queue(), ^ { | |
returnBlock(); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment