Created
January 2, 2013 19:57
-
-
Save codeswimmer/4437404 to your computer and use it in GitHub Desktop.
iOS: How to use NSThread
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
| Create Thread | |
| [NSThread detachNewThreadSelector:@selector(myMethod) toTarget:self withObject:nil]; | |
| Create a selector method called by our thread | |
| - (void)myMethod { | |
| NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | |
| // code here | |
| [pool release]; | |
| } | |
| Note: If you want to do something to the main thread inside your new thread, use performSelectorOnMainThread. | |
| [self performSelectorOnMainThread:@selector(myMethod) withObject:nil waitUntilDone:false]; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment