Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Value of type 'DispatchQueue' has no member 'asynchronously' - Swift 3

I just updated my xcode8 to Swift 3 and I received this error:

Value of type 'DispatchQueue' has no member 'asynchronously'

on this line:

   DispatchQueue.main.asynchronously(execute:

Here's the entire snippet:

  DispatchQueue.main.asynchronously(execute: {

                        //Display alert message with confirmation
                        let myAlert = UIAlertController(title: "Alert", message:messageToDisplay, preferredStyle: UIAlertControllerStyle.Alert);




                        let okAction = UIAlertAction(title:"OK", style:UIAlertActionStyle.Default){

                            action in self.dismissViewControllerAnimated(true, completion:nil);

                        }

                        myAlert.addAction(okAction)
                        self.presentViewController(myAlert, animated:true, completion:nil);
                    });
                }
            }
            catch let error as NSError {
                print(error.localizedDescription)
            }

        }

        task.resume()

}
}

Recently updating to Swift 3 has given me a lot of errors, they automatically fixed but this one will not fix on its own and I do not know what to do.

like image 986
PHP Web Dev 101 Avatar asked Oct 02 '16 20:10

PHP Web Dev 101


1 Answers

In the production release of Swift 3 and iOS 10, there is no asynchronously method. It's just async:

DispatchQueue.main.async {
    //Display alert message with confirmation
    let alert = UIAlertController(title: "Alert", message: messageToDisplay, preferredStyle: .alert)

    let okAction = UIAlertAction(title: "OK", style: .default) { action in
        self.dismiss(animated: true)
    }

    alert.addAction(okAction)
    self.present(alert, animated: true)
}
like image 159
Rob Avatar answered Nov 16 '22 23:11

Rob