In Swift 2, I was able to create queue with the following code:
let concurrentQueue = dispatch_queue_create("com.swift3.imageQueue", DISPATCH_QUEUE_CONCURRENT)
But this doesn't compile in Swift 3.
What is the preferred way to write this in Swift 3?
Compiles under Swift 3. This example contains most of the syntax that we need.
QoS - new quality of service syntax
weak self
- to disrupt retain cyclesif self is not available, do nothing
async global background queue
- for network queryasync main queue
- for touching the UI.Of course, you need to add some error checking to this...
Creating a concurrent queue
Create a serial queue
Get main queue asynchronously
Get main queue synchronously
To get one of the background thread
Xcode 8.2 beta 2:
To get one of the background thread
If you want to learn about using these queues .See this answer
I re-worked your code in Xcode 8, Swift 3 and the changes are marked in contrast to your Swift 2 version.
For Swift 3
I did this and this is especially important if you want to refresh your UI to show new data without user noticing like in UITableView or UIPickerView.
Swift 3
you want call some closure in swift code then you want to change in storyboard ya any type off change belong to view your application will crash
but you want to use dispatch method your application will not crash
async method
sync method