Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?""

like image 459
Deidara Avatar asked Dec 10 '22 15:12

Deidara


1 Answers

EDIT: For Swift 3, change it to

present(alert, animated: false, completion: nil)

You called the wrong function.

Should be

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

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

like image 199
Happiehappie Avatar answered Feb 11 '23 18:02

Happiehappie