In front of the iOS Nsthread method to implement multi-threading, this is simply about Nsoperation and nsoperationqueue.
Nsoperation is an abstract class that defines a task to perform. Nsoperationqueue is a task queue that helps manage the tasks defined by Nsoperation. When a task is added to the task queue, it automatically runs automatically by priority and dependency.
Nsoperation is not used directly, we must use the inheriting class. iOS provides two well-implemented subclasses, namely Nsinvocationoperation and nsblockoperation. Nsoperation has a Start method that gives you a way to run a task without joining the Nsoperationqueue, which is, of course, a bit higher for developers.
I still use the same function as an example, on the code:
-(void) viewdidload{ [Super Viewdidload]; Object : Image_url]; *queue = [[Nsoperationqueue alloc] init]; [Queue addoperation:operation];}
It looks simple, just create a task and then join the queue. This queue is a task pool that follows the producer-consumer relationship and automatically runs the task when there is a task. We can use Setmaxconcurrentoperationcount: This method to set the total number of threads in this queue, the default value is-1, meaning there is no limit.
iOS multithreaded-nsoperation