Search code examples
iosgrand-central-dispatchnsoperationnsoperationqueue

NSOperationQueue vs NSOperation vs GCD


In what cases would you prefer to use NSOperationQueue or NSOperation or GCD. I have just started working in thread so what are the benefits and time complexity. When we need to use which one and what are the benefits and in which cases we need to consider which one .


Solution

  • GCD is low level C-based API.

    NSOperation and NSOperationQueue are Objective-C classes that are based on GCD and simplify execution prioritisation and cancellation.

    Advantages of NSOperationQueue over GCD include:

    1. It is easy to cancel or suspend an operation if it is in queue it can be stopped if it is running.

    2. You can define the maximum number of concurrent operations.

    3. You can make dependencies between distinct instances of NSOperation.