I am developing in Swift 2.3
I have an Utils class enabling me to create UIAlertController easily.
public class Utils {
cl
To be more Specific and use that method in any class of project. For this make a function in NSObject class. Like:
open class func showAlert(_ delegate: UIViewController, message: String ,strtitle: String, handler:((UIAlertAction) -> Void)! = nil)
{
let alert = UIAlertController(title: strtitle, message: message, preferredStyle: UIAlertControllerStyle.alert)
if handler == nil{
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
}
else
{
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: handler))
}
delegate.present(alert, animated: true, completion: nil)
}
In Controller I will call the method and do the required work like:
Alert.showAlert(self, message: "Message", strtitle: "Tittle!!", handler: {
(action : UIAlertAction) in
//Do your Work here
})
Note: Here Alert is name of NSObject class.