rv7284
5/15/2017 - 11:56 AM

Show UIAlertViewController

Show UIAlertViewController

func showAlertControllerWithTitle(title: String, message: String,actions: [String], alertStyle: UIAlertControllerStyle, callback:@escaping (_ actionIndex: Int) -> Void) {
    let alertController : UIAlertController = UIAlertController(title: title, message: message, preferredStyle: alertStyle)
    for title in actions{
      
        let action : UIAlertAction!
            
        if title.caseInsensitiveCompare("cancel") == ComparisonResult.orderedSame {
            action = UIAlertAction(title: title, style: .cancel, handler: { (action) in
                    callback(actions.index(of: title)!)
            })
        } else {
            action = UIAlertAction(title: title, style: .default, handler: { (action) in
                callback(actions.index(of: title)!)
            })
        }
        alertController.addAction(action)
    }
    self.window?.topMostController()?.present(alertController, animated: true, completion: nil)
}