Skip to content

Instantly share code, notes, and snippets.

@genedelisa
Created August 11, 2014 19:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save genedelisa/9bf44469c7f40772f5d1 to your computer and use it in GitHub Desktop.
Save genedelisa/9bf44469c7f40772f5d1 to your computer and use it in GitHub Desktop.
UIAlertController in Swift
// ios8 and later
var alert = UIAlertController(title: "Hey!",
message: "How 'bout dat?",
preferredStyle: .Alert)
let textConfigClosure: ((UITextField!) -> Void)! = { text in
text.placeholder = "Type something here"
}
alert.addTextFieldWithConfigurationHandler(textConfigClosure)
alert.addTextFieldWithConfigurationHandler({textfield in
textfield.placeholder = "foo"
})
alert.addAction(UIAlertAction(title: "Confirm", style: .Default, handler: {action in
println("confirm was tapped")
}))
let otherClosure: ((UIAlertAction!) -> Void)! = { action in
println("other was tapped")
let tf = alert.textFields[0] as UITextField
println(tf.text)
}
alert.addAction(UIAlertAction(title: "Other", style: .Default, handler: otherClosure))
self.presentViewController(alert, animated:true, completion:nil)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment