iOS Concurrency with GCD & Operations

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

Part 3: Operations & OperationQueues

17. Challenge: TiltShiftOperations in OperationQueue

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: 16. OperationQueues Next episode: 18. Asynchronous Operations

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.

Challenge: TiltShiftOperations in OperationQueue

The playground in the starter folder has an array of input images, an empty filteredImage array to hold the tilt-shifted output images and the TiltShiftOperation subclass from video 15. Use this operation in an OperationQueue to filter all the input images.

let appendQueue = OperationQueue()
appendQueue.maxConcurrentOperationCount = 1
let filterQueue = OperationQueue()
let filterOp = TiltShiftOperation(image: image)
filterQueue.addOperation(filterOp)
filterOp.completionBlock = {

}
guard let output = filterOp.outputImage else { return }
appendQueue.addOperation {
  filteredImages.append(output)
}
filterQueue.waitUntilAllOperationsAreFinished()
filteredImages
// In case the playground won't display the array of images:
filteredImages[0]
filteredImages[1]
filteredImages[2]
filteredImages[3]
filteredImages[4]
[w 1,024 h 768, w 1,024 h 1,176, w 1,024 h 768, w 1,024 h 768, w 1,024 h 768]