【swift】UIAlertControllerを表示してみる

シンプルなUIAlertControllerを表示するサンプルです

タイトル・メッセージは任意の文字列へ変更してください

各ボタンをタップした場合のアクションも任意です

let alert = UIAlertController(
    title: "Alert Title",
    message: "Alert Message",
    preferredStyle: .alert
)
        
alert.addAction(UIAlertAction(title: "Button1", style: .default, handler: { _ in
    //Button1をタップしたときのアクション
}))
   
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: { _ in
    //Cancelをタップしたときのアクション
}))
        
//AlertControllerを表示する
self.present(alert, animated: true, completion: nil)

実行スクリーンショット