Skip to content

Instantly share code, notes, and snippets.

@codeswimmer
Created January 2, 2013 19:57
Show Gist options
  • Select an option

  • Save codeswimmer/4437404 to your computer and use it in GitHub Desktop.

Select an option

Save codeswimmer/4437404 to your computer and use it in GitHub Desktop.
iOS: How to use NSThread
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