27 Nov 2017

How to Create a Global UIAlertController in Swift...


 Add this code in any Class (As UIViewController extension)  as shown below

extension UIViewController {
    
    func alert(message: String, title: String ) {
        let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
        let OKAction = UIAlertAction(title: "OK", style: .default, handler: nil)
        alertController.addAction(OKAction)
        self.present(alertController, animated: true, completion: nil)
    }
    

}


and call it anywhere(In  Any ViewController) as shown below,

   
self.alert(message: "Some message", title: "Title of Alert")

No comments:

Post a Comment

Recent Posts

Codable demo

Link: https://www.dropbox.com/s/kw7c1kgv1628bh7/codableDemo.zip?dl=0