私はObjective Cを初めて使っていますが、今すぐSwiftに取り組んでいます。私はObjective cを論理的にswiftと似ていると仮定しました。私は、jsonのデータ要求を処理している間に警報コントローラを提示する必要があります。だから私は迅速に動作するようにディスパッチ非同期を使用しなければならなかった。ここで私はスウィフトで使用されるコードです:ディスパッチ非同期コードエラー - 目的C
func alertMessage(message : String) -> Void {
let alert = UIAlertController(title: "Alert", message: message, preferredStyle: .Alert)
let okAction = UIAlertAction(title: "OK", style: .Default, handler: nil)
alert.addAction(okAction)
dispatch_async(dispatch_get_main_queue(),{
self.presentViewController(alert, animated: true, completion: nil)
})
}
は、しかし、私はそう
- (void)alertMessage : (NSString*) message {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Alert" message:message preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:NULL];
[alert addAction:okAction];
[dispatch_async(dispatch_get_main_queue(), ^(void){
[self presentViewController:alert animated:true completion:NULL];
})];
}
私は「識別子を期待される」エラーを取得していますように客観Cで同じことを実行しようとしました。私は間違って何をしていますか?
[自己presentViewController:アラートのアニメーション:真完了:nilを];これが問題を引き起こしている可能性があります。NULLをnilに置き換えます。 –
エラーが発生している行はありますか? – Arun
@Arunの2行目の最後の行}}]; ] –