NSOpertaionQueue
Building encapsulation with GCD is a high-level abstraction of GCD.
GCD only supports FIFO queues, while queues in Nsoperationqueue can be prioritized to perform order adjustments for different operations.
GCD does not support dependency settings between asynchronous operations. If an operation relies on data from another operation (the producer-consumer model is one of them), use Nsoperationqueue to perform the operation in the correct order. GCD does not have built-in dependency support.
Nsoperationqueue supports KVO, which means that we can observe the execution state of a task.
To understand the above differences, we can define the principles from the following perspectives
1. Performance
GCD is closer to the bottom, while Nsoperationqueue is more advanced abstraction, so GCD is the fastest in the pursuit of performance-underlying operations. This depends on using instruments for code performance analysis, if necessary
2. Transactional, sequential line, dependency between asynchronous operations. GCD needs to write more code to implement it, and Nsoperationqueue has built in these support
3. Nsoperationqueue is a better choice if the process of an asynchronous operation requires more interaction and UI rendering. In the underlying code, the tasks are less dependent on each other and require higher concurrency, and the GCD is more advantageous
GCD and Nsoperationqueue differences