Group Group Group Group Group Group Group Group Group

iOS Concurrency with GCD and Operations - Part 6: | Ray Wenderlich

In this video tutorial you'll learn how to use OperationQueue to handle the scheduling and execution of Operations.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/3648-ios-concurrency-with-gcd-and-operations/lessons/6

:slight_smile: Hi … There’re some issue in the Demo starter project:
=> missing TiltShiftOperation class.

This class is included In Demo finished project in TiltShift.swift file :wink:

thanks Ilmars! I’ve added this to my errata list :+1:

Don’t know if others are seeing this but Xcode (9.3, 9E145) crashes whenever I hit the quicklook or show result buttons for the filteredImages array. Other objects seem to display fine.

I haven’t installed High Sierra or 9.3 yet. In a hotel for several days, so not optimistic about installing either until I get home, middle of next week. But it doesn’t surprise me :slight_smile:

1 Like

Confirmed. Still an issue in 9.3.1.

I run OperationQueue of 06_DemoFinished on Xcode 10.1 that I can’t see any result of filteredImages by clicking Quick Look.

I try to debug that I add print function to print logs in the operation of appendQueue before appending output to filteredImages. But filteredImages’s count less than five.

hi! as noted in earlier posts, quick look for these images stopped working in Xcode 9. I’m running Xcode 11 beta 7, and it doesn’t crash, but it doesn’t show the images either. However, the output next to filteredImages is an array of 5 images:

[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]

I’ll be updating this course soon. In the meantime, you could look at our book, which is up to date for Xcode 10.

As I remember that you mentioned that OperationQueues are concurrent.
but anytime I did following
even with changed sleep time. it print it out in order.
duration {
printerQueue.addOperation { print(“hello”); sleep(3) }
printerQueue.addOperation { print(“my”); sleep(4) }
printerQueue.addOperation { print(“name”); sleep(1) }
printerQueue.addOperation { print(“is”); sleep(2) }
printerQueue.addOperation { print(“Alok”); sleep(3) }
}

why task would be finishing in sequential order. What am I missing, Audrey?

Hi Alok! You might have maxConcurrentOperationCount set to 1?

They are already in order. how MaxConcurrentOperationCount = 1 is going to help?

Also demo finished doesn’t show the filter images(using Xcode 11.3.1), demo starter is missing TiltShiftOperation too.

if you have MaxConcurrentOperationCount = 1, then the operation queue is a serial queue, so no matter how you set the sleep times, the operations will run in the order you added, and the total duration will be a little more than the sum of the sleep times.

if you have MaxConcurrentOperationCount > 1, the queue can run more than one operation at the same time, so the print statements will more likely be out of order.

the quicklook bug has been in Xcode since Xcode 9; it still doesn’t work for an array of images, but you can view a single image:

filteredImages[0]

You’re right about TiltShiftOperation being missing from the starter playground. I’ll fix it in the update. Thanks!

Thats what I am trying to find out, When I don’t specify maxConcurrentOperationCount. its by default concurrent queue. if it is then why “my name is Alok”, would print in order. when they have different sleep times are ranging from 2 to 4.
that part is not making sense to me. Am I missing something?
Did I explain it well?

is the duration 13 seconds? or less?