Created
January 12, 2016 13:56
-
-
Save bouchtaoui-dev/cf65974c317d8ee02076 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| dispatch_queue_t myQueue = dispatch_queue_create("my queue",NULL); | |
| //... | |
| //... | |
| //... | |
| dispatch_async(imageQueue, ^{ | |
| // This will run the method in a separate thread | |
| [self doSomeLongRunningTask]; | |
| }); | |
| - (void) doSomeLongRunningTask { | |
| dispatch_async(dispatch_get_main_queue(), ^{ | |
| NSLog(@"We finished a heavy task!"); | |
| }); | |
| } | |
| /* | |
| So, we create a dispatch queue handle for our separated thread, | |
| than pass a block ^{} to dispatch_async that will be executed in a separate thread ( NOT in the main thread). | |
| If you want to call a method in the main thread from another thread, | |
| you call: dispatch_async(dispatch_get_main_queue(), ^{ }); | |
| As you see, dispatch_get_main_queue() gives you the queue handle of the main thread. | |
| For more information, check: | |
| http://en.wikipedia.org/wiki/Grand_Central_Dispatch | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment