Browse Questions
  • OperationQueue is a higher-level abstraction over GCD.
  • @MainActor is a global actor that ensures code runs on the main thread.
  • Use separate Xcode Schemes, Build Configurations, Bundle Identifiers, and Firebase plists — one set per environment.
  • Classic OOP centers on classes and inheritance hierarchies — behavior is shared by subclassing a base class.

Answer: OperationQueue is a higher-level abstraction over GCD. It adds features like dependencies between operations, cancellation, and maximum concurrency limits.

OperationQueueGCD
Dependencies✅ Yes❌ No
Cancellation✅ YesLimited
Max concurrency✅ YesLimited
KVO observable✅ Yes❌ No
OverheadHigherLower

Code Example:

let queue = OperationQueue()
queue.maxConcurrentOperationCount = 3

let op1 = BlockOperation { print("Download image") }
let op2 = BlockOperation { print("Process image") }
let op3 = BlockOperation { print("Save image") }

// op2 and op3 won't start until op1 finishes
op2.addDependency(op1)
op3.addDependency(op2)

queue.addOperations([op1, op2, op3], waitUntilFinished: false)

// Cancel all
queue.cancelAllOperations()