Tung Fam Tung Fam - 1 month ago 9x
iOS Question

Queues and Swift 3 issue

Please help me to convert this line to swift 3.0:

dispatch_async(DispatchQueue.global(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0))

And what does it exactly mean? Something like: do the code in brackets in the main queue?

Thanks in advance.

ps. This line of code was taken from apple's code to work with core data


In Swift 3 You can write like this

DispatchQueue.global(qos: .background).async {


It means what every the code written in between the bracket will perform in the background. and if you want to make any changes in this background thread you have to switch to the main thread. by writing the block below.

dispatch_async(dispatch_get_main_queue()) { 
     // Your code for UI Changes.

EDIT: Swift 3

DispatchQueue.main.async {