Merhaba bu yazıda Swift 5 ile iOS’ta nasıl alert dialog gösterebileceğimizi öğreneceğiz.
// alert oluşturuldu let alert = UIAlertController(title: "Başlık", message: "Mesajım.", preferredStyle: UIAlertController.Style.alert) // alerte button eklendi alert.addAction(UIAlertAction(title: "Tamam", style: UIAlertAction.Style.default, handler: nil)) // alert gösterildi self.present(alert, animated: true, completion: nil)

// alert oluşturuldu let alert = UIAlertController(title: "Başlık", message: "Mesajım.", preferredStyle: UIAlertController.Style.alert) // alert'e button eklendi alert.addAction(UIAlertAction(title: "Tamam", style: UIAlertAction.Style.default, handler: nil)) alert.addAction(UIAlertAction(title: "İptal", style: UIAlertAction.Style.cancel, handler: nil)) // alert gösterildi self.present(alert, animated: true, completion: nil)

Alert buttonuna tıklanıldığı zaman ki listener’ı da şu şekilde dinleyebiliriz.
alert.addAction(UIAlertAction(title: "Tamam", style: UIAlertAction.Style.destructive, handler: { action in //alert button tıklandı }))