One of the most common task in Grand Central Dispatch (GDC) pattern is performed work on a global background queue and update the UI on the main queue as soon as the work is done.The new API looks like this:
DispatchQueue.global(attributes: [.qosDefault]).async {
// Background thread
DispatchQueue.main.async(execute: {
// UI Updates
})
}
Queues now take attributes on init. This is a Swift optionSet and can include queue options such as serial vs concurrent, memory and activity management option and the quality of service (.default, .userInteractive, .userInitiated, .utility and .background).
New changes:
- DISPATCH_QUEUE_PRIORITY_HIGH: -> .userInitiated
- DISPATCH_QUEUE_PRIORITY_DEFAULT: -> .default
- DISPATCH_QUEUE_PRIORITY_LOW: -> .utility
- DISPATCH_QUEUE_PRIORITY_BACKGROUND: -> .background
if you want to learn more about, this is a good talk https://developer.apple.com/videos/play/wwdc2016/720/