here´s a sample code with two actions plus and ok-action:
import UIKit
// The UIAlertControllerStyle ActionSheet is used when there are more than one button.
@IBAction func moreActionsButtonPressed(sender: UIButton) {
let otherAlert = UIAlertController(title: "Multiple Actions", message: "The alert has more than one action which means more than one button.", preferredStyle: UIAlertControllerStyle.ActionSheet)
let printSomething = UIAlertAction(title: "Print", style: UIAlertActionStyle.Default) { _ in
print("We can run a block of code." )
}
let callFunction = UIAlertAction(title: "Call Function", style: UIAlertActionStyle.Destructive, handler: myHandler)
let dismiss = UIAlertAction(title: "OK", style: UIAlertActionStyle.Cancel, handler: nil)
// relate actions to controllers
otherAlert.addAction(printSomething)
otherAlert.addAction(callFunction)
otherAlert.addAction(dismiss)
presentViewController(otherAlert, animated: true, completion: nil)
}
func myHandler(alert: UIAlertAction){
print("You tapped: \(alert.title)")
}}
with i.E. handler: myHandler you define a function, to read the result of
the let printSomething.
This is just one way ;-)
Any questions?