Showing an alert view in Swift causes EXC BAD ACCESS
ios, swift
Solution
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)
Problem
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?