Nsoperation is an abstract class, it can be used directly using the system provides two sub-classes: Nsinvocationoperation, nsblockoperation, you can also write a class, inherit nsoperation.
There are 2 forms of nsoperation: Concurrent, non-concurrent
(1) Concurrent execution
Concurrent execution you need to overload the following 4 methods
-(void) Start//Execute task main function, thread run entry function
-(BOOL) isconcurrent//whether to allow concurrency, return yes, allow concurrency, return no not allowed. Default returns NO
-(BOOL) isexecuting
-(BOOL) isfinished//Whether has been completed, this must be overloaded, or put in the nsoperationqueue in the nsopertaion can not be released normally
For example, Testnsoperation:nsoperaion overloads the above 4 methods, declares a nsoperationqueue,
Nsoperationqueue *queue = [[[[Nsoperationqueue alloc] init] autorelease];
[Queue addoperation:testnsoperation];
Once an operation is queued, the queue starts and processes it (that is, the main method that invokes the action Class). Once the operation completes the queue, it is freed. In this example, it automatically calls the start function in Testnsoperation.
If you need more than one nsoperation, you need to set some properties of the queue, and if there are dependencies between multiple nsoperation, you can also set it up, refer to the API documentation.
You can set up the number of operations that a colleague runs on the operations queue: [Queue setmaxconcurrentoperationcount:2];
iOS Multi-threaded series (ii)------nsoperation and Nsoperationqueue