Monday, May 9, 2011

NSThread example objc

A NSThread example that is very  simple.
Let's create and run a NSThread object on iPhoneOS.
First you should write a method that runs as a thread [NSThread Example]

1-(void) myTestThread:(id)anObject {
2
3     NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init];
4     //Your code here..
5     
6    [autoreleasepool release];
7    [NSThread exit];
8
9}


Then create a new NSThread object with detachNewThreadSelector method as following
code fragment. That's all pretty simple! [NSThread Example]

[NSThread detachNewThreadSelector:@selector(myTestThread:) toTarget:self withObject:nil];