Friday, April 19, 2013

NSThread exit example objc

[NSThread exit example]

Create a NSThread object with following code fragment.

NSThread *newThread = [[NSThread alloc] initWithTarget:self selector:@selector(MyThread:) object:timer];

To exit this thread externally, you can call NSThread:cancel method at some point and make your main thread method to check for whether it's cancelled or not by calling NSThread:isCancelled method.[NSThread exit example]

In your main thread method, you should check whether it's cancelled or not periodically.

// At some checkpoint

if([[NSThread currentThread] isCancelled])
{
   /* do some clean up here */
   [NSThread exit];
}