2016-10-02 20 views
7
Sadece Swift 3 benim xcode8 güncellenmiş ve bu hatayı aldım

:Değer 'uyumsuz' hayır üyesi var - Swift 3

DispatchQueue.main.asynchronously(execute: 

: Bu satırda

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

İşte tüm parçacık İşte:

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() 

} 
} 

son Swift 3'e güncelleme bana hataların çok vermiştir, bunlar otomatik sabit ama Bu kendi başına düzeltmeyecek ve ne yapacağımı bilmiyorum.

+5

kullanım DispatchQueue.main.async (...) – AleyRobotics

+0

@Yuri ne demek istiyorsun? Zaten böyle kodlanmış değil mi? –

+0

"Eşzamansız" adı, yöntem için eski bir adaydı ve "async" olarak yeniden adlandırıldı. – OOPer

cevap

17

Swift 3 ve iOS 10'un üretim sürümünde asynchronously yöntemi yoktur. Sadece async var:

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) 
}