iOS Concurrency with GCD & Operations

Sep 12 2023 · Swift 5.8, macOS 13, iOS 16, Xcode 14.3

Part 3: Operations & OperationQueues

16. OperationQueues

Episode complete

Play next episode

Next
About this episode
Leave a rating/review
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 15. Operations Next episode: 17. Challenge: TiltShiftOperations in OperationQueue

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

In this video you’ll discover that the real power of Operations is when you add them to an OperationQueue. Instead of starting the operation yourself, you’ll hand it over to an operation queue and let it handle scheduling and execution.

let printerQueue = OperationQueue() // pause at ( to show initializer
duration {
  printerQueue.addOperation { print("Hello"); sleep(3) }
  printerQueue.addOperation { print("my"); sleep(3) }
  printerQueue.addOperation { print("name"); sleep(3) }
  printerQueue.addOperation { print("is"); sleep(3) }
  printerQueue.addOperation { print("Audrey"); sleep(3) }
}
(in side pane: duration 0.0001649856567382812)
Hello
my
name
is
Audrey
duration {
  printerQueue.waitUntilAllOperationsAreFinished()
}
duration 3.006882905960083 <in side pane> 
printerQueue.maxConcurrentOperationCount = 2
duration 9.008874893188477 <in side pane>