Artificial intelligent assistant

UIAlertControllerで押されたボタンをTrue/Falseで取得したい UIAlertControllerOKActionSheet OKtruefalse /// class func confirm(vc: UIViewController, strMsg: String, strTitle: String = "") -> Bool { var ret: Bool = true let dialog = UIAlertController(title: strTitle, message: strMsg, preferredStyle: .ActionSheet) let act1 = UIAlertAction(title: "OK", style: .Default) { action in ret = true } let act2 = UIAlertAction(title: "", style: .Cancel) { action in ret = false } dialog.addAction(act1) dialog.addAction(act2) vc.presentViewController(dialog, animated: true, completion: nil) return ret }

true/false


extension UIViewController {
///
func confirm(strMsg: String, strTitle: String = "", handler: Bool->Void) {
let dialog = UIAlertController(title: strTitle, message: strMsg, preferredStyle: .ActionSheet)
let act1 = UIAlertAction(title: "OK", style: .Default) { action in
handler(true)
}
let act2 = UIAlertAction(title: "", style: .Cancel) { action in
handler(false)
}
dialog.addAction(act1)
dialog.addAction(act2)

self.presentViewController(dialog, animated: true, completion: nil)
}
}


UIViewControllerextensionUIViewController




@IBAction func deleteRecord(_: AnyObject) {
//
//...
confirm("", handler: {confirmed in
if confirmed {
//
//...
} else {
//
}
})
//
}

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 2f8174e2b47004e2f79d9ac5fbefcaaf