UIAlertController UITextField Bug

There are times when you want to display a UITextField inside the UIAlertController. You can use the following code: 

 @IBAction func openAddNewItemDialog() {
let alertController = UIAlertController(title: "Add New Item", message: "", preferredStyle: UIAlertControllerStyle.Alert)
alertController.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: { (action :UIAlertAction) -> Void in
if let textField = alertController.textFields?.first {                
alertController.addTextFieldWithConfigurationHandler { (textField :UITextField) -> Void in
// configure the textbox
textField.placeholder = "Add new task"
self.presentViewController(alertController, animated: true, completion: nil)

Unfortunately, the above code will lead to a message in the console as shown below: 

This is a bug in the UIAlertController and how it displays the UITextField. In order to silence the warning you can add the following just before presenting the controller. 


Happing coding!