Dear Friends,
Today I will show you how to create a simple alert with two buttons and how to write a callback for each button. The code is simple. Its written for Swift 3.

 func showErrorAlert(VC vc : UIViewController, OKTitle okTitle : String, CancelTitle cancelTitle : String, Message message : String, Title title : String) -> Void {
        let alertController = UIAlertController(
            title: title,
            message: message,
            preferredStyle: UIAlertControllerStyle.alert
        let cancelAction = UIAlertAction(
            title: cancelTitle,
            style: UIAlertActionStyle.destructive) { (action) in
   Notification.Name("CancelClicked"), object: nil)
        let confirmAction = UIAlertAction(
        title: okTitle, style: UIAlertActionStyle.default) { (action) in
   Notification.Name("OKClicked"), object: nil)
        vc.present(alertController, animated: true, completion: nil)

Send your comments to


Leave a Reply

Your email address will not be published. Required fields are marked *




Theme by HermesThemes

Copyright © 2018 CoderzHeaven. All Rights Reserved

Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.