When I define the UIAlertController convenience UIAlertController :
extension UIAlertController { convenience init(message: String?) { self.init(title: nil, message: message, preferredStyle: .Alert) self.addAction(UIAlertAction(title: "OK", style: .Cancel, handler: nil)) } }
and use it in the button action in my subclass of UIViewController :
func buttonAction(button: UIButton) { let alert = UIAlertController(dictionary: nil, error: nil, handler: nil) presentViewController(alert, animated: true, completion: nil) }
and press this button on the simulator, I get a warning:
Attempting to load a view controller view while it is free is not allowed and may result in undefined behavior (UIAlertController)
However, I do not receive a warning if, instead of a convenience initializer, I use a global function:
func UIAlertControllerWithDictionary(message: String?) -> UIAlertController { let alert = UIAlertController(title: nil, message: message, preferredStyle: .Alert) alert.addAction(UIAlertAction(title: "OK", style: .Cancel, handler: nil)) return alert }
I reported this to Apple as an SDK error for iOS.
Until it is fixed, is it okay to ignore the warning and use the convenience initializer?