Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ambiguous use of 'dispatch_get_main_queue()'

How do I replace the following Swift code for iOS using the DispatchQueue class? This is old Swift 3 code that the newest Xcode won't convert to Swift 5.

dispatch_async(dispatch_get_main_queue()) { () -> Void in
  // code
}

It is giving me an error that says

Ambiguous use of 'dispatch_get_main_queue()'

for dispatch_get_main_queue().

The following answer seems to be the right answer, and I want to use it, but could someone tell me this is correct? Swift version

It says to use the following code:

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

    // Background Thread

    DispatchQueue.main.async {
        // Run UI Updates
    }
}

Other than using DispatchQueue, what other alternative do I have to fix this error?

like image 202
Daniel Brower Avatar asked Apr 20 '19 21:04

Daniel Brower


1 Answers

Yes, it is correct. That's the new updated syntax.

like image 142
Tom Pearson Avatar answered Nov 05 '22 15:11

Tom Pearson