No more pitfalls! NSOperation is the multithreading technology that Apple recommends !, Nsoperation Multithreading
First of all, let me declare that I like GCD more in actual development, because it is more convenient to use.
But what is the truth?
Apple actually recommends NSOperation, so I hope you will not mislead others in your blog.
In other words, the Objective-C language used by Apple Development Is Object-Oriented. How can she recommend process-oriented development based on C language? (This sentence is just a joke. Do not spray it ...)
About NSOperation
Many people, when talking about NSOperation in their blogsIt was launched by iOS2.0.This emphasizes that the later GCD released by iOS4.0 is the multithreading method recommended by Apple!
I don't think I can blame them all for this, because many people are learning through data query during development, and few are willing to read the information provided by Apple.Official documentation.
In fact, Apple specifically mentioned this in the official documentation that NSOperation was indeed launched by iOS2.0. At that time, NSOperation was implemented through NSThread, and the efficiency was indeed average, !!
After Apple launched GCD in iOS4.0, it rewritten NSOperation. Since then, the underlying NSOperation is implemented by GCD !!
Below is the original official document:
(Operation queues usually provide the threads used to run their operations. In OS X v10.6 and later, operation queues use the libdispatch library (also known as Grand Central Dispatch) to initiate the execution of their operations. As a result, operations are always executed on a separate thread, regardless of whether they are designated as concurrent or non-concurrent operations. In OS X v10.5, however, operations are executed on separate threads only if their isConcurrent method returns NO. If that method returns YES, the operation object is expected to create its own thread (or start some asynchronous operation); the queue does not provide a thread for it.)
Comparison between NSOperation and GCD:
Apple no longer limits the maximum number of concurrent threads.
That is to say, this is not good for GCD development, because GCD cannot control the maximum number of concurrent threads, and once the number of concurrent threads is too large... You know ~
So, in summary, Apple actually recommends that we use NSOperation in the development process, not GCD! Please pay attention to it during development ~