Monday, May 9, 2011

NSInvocationOperation example objc

An NSInvocationOperation example. You can make a thread-like effect using NSInvocationOperation class. See Following code fragment.


First create a NSInvocationOperation object.
01: NSInvocationOperation* op =
02: [[[NSInvocationOperation alloc]
03: initWithTarget:self
04: selector:@selector(myMethod:) object:data] autorelease];
Next, you run the NSInvocationOperation object by queueing it into new NSOperationQueue object.
01: NSOperationQueue* queue = [[NSOperationQueue alloc] init];
02: [queue setMaxConcurrentOperationCount:1];
03: [queue addOperation:op];