Use Dispatch Work Items | raywenderlich.com


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

Hey Audrey! Thank you for the tutorial.
I have a question here.
Why did we use quality of service as ‘utility’ for the global DispatchQueue to download the image? Could we have also used ‘userInitiated’ here? Would it make a big difference if we use one or the other? Thanks.

hi Shruti! userInitiated is for tasks that run in response to an actual action by the user, like tapping a button. In the Concurrency app, the download tasks just populate the collection view, so it’s more of a background activity.

userInitiated for all the image downloads would probably use more battery power than utility

Note: This question is about Episode 5.

Thanks Audrey. So we don’t use background qos in that case because it is a time sensitive high priority task which the user is aware of and not any background task like database management, synchronizing, and backups.

hi Shruti: yes, background is for tasks that don’t really affect the user experience.

I totally did not understand the point of:

dispatchPrecondition(condition: .onQueue(DispatchQueue.main))

In the playground, we are already on the main queue… so what does this actually do?

hi Jason! it’s just to show you this useful method exists and how it works. It was new in Swift 4.