I have the following view controller. It simply reads from a text field a value to display in a UIAlertView
.
import UIKit
class ViewController: UIViewController {
@IBOutlet var textField: UITextField!
@IBAction func pressButton(sender: UIButton) {
let name = textField.text
let alert = UIAlertView(
title: "Hello!",
message: "How are you today, \(name). I'm lovely!",
delegate: nil,
cancelButtonTitle: "Thanks!"
)
alert.show() // EXC_BAD_ACCESS
}
}
Why does alert.show()
crash with EXC_BAD_ACCESS
? What's happening here to my instance of UIAlertView
? Why isn't it in alert
like I think it should be?
Try to use var instead of lat as following
var alert = UIAlertController(title: "Title", message: "Message", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With