Deidara Deidara - 4 months ago 152
iOS Question

Cannot call value of non-function type "UIViewController?"

I want to make an alert dialog showing up with messages and here's my code in ViewController.swift:

func showErrorAlert(title: String , msg: String){
let alert = UIAlertController(title: title, message: msg, preferredStyle: .Alert)
let action = UIAlertAction(title: "OK", style: .Default, handler: nil)
alert.addAction(action)
presentedViewController(alert, animated: true, completion: nil)
}


The last line is giving me an error:


"Cannot call value of non-function type "UIViewController?""

Answer

You called the wrong function.

Should be

presentViewController(alert, animated: true, completion: nil)

Instead of presentedViewController(alert, animated: true, completion: nil)

Comments