I have an app that worked with Swift 1, when I converted to Swift 2 the alert action is displayed briefly then it disappears before the user has time to enter anything into the 2 text fields and before the OK button is pressed.
var inputLatitude: UITextField?
var inputLongitude: UITextField?
let alertController = UIAlertController(title: "Location Manager Error", message: "Enter location manually", preferredStyle: .Alert)
alertController.addTextFieldWithConfigurationHandler({(textField: UITextField!) in
textField.placeholder = "Latitude"
inputLatitude = textField})
alertController.addTextFieldWithConfigurationHandler({(textField: UITextField!) in
textField.placeholder = "Longitude"
inputLongitude = textField})
let okAction = UIAlertAction(title: "OK", style: .Cancel, handler: { (action) -> Void in
if let userInfo = inputLatitude?.text {
self.stringLatitude = userInfo
}
if let userInfo2 = inputLongitude?.text {
self.stringLongitude = userInfo2
}
print(inputLatitude?.text)
print(inputLongitude?.text)
})
alertController.addAction(okAction)
presentViewController(alertController, animated: true, completion: nil)
foundLatitude.text = stringLatitude
foundLongitude.text = stringLongitude