Mehrdad
Mehrdad

Reputation: 1208

Use of unresolved identifier 'present' - the present method doesn't work anymore

I'm going to use UIAlertController but when I want to present it I see this error:

use of unresolved identifier 'present'

This is my code :

func showAllert(title: String, msg: String, vc: UIViewController){
    let alert = UIAlertController(title: title, message: msg, preferredStyle: .alert)
    let action = UIAlertAction(title: "ok", style: .default, handler: nil)
    alert.addAction(action)

    present(alert, animated: true, completion: nil)
}

Upvotes: 2

Views: 7168

Answers (2)

Kirill  Dubovitskiy
Kirill Dubovitskiy

Reputation: 306

If you want to specifically use vc: UIViewController to present the alert you should call the method this way:

vc.present(alert, animated: true, completion: nil)

Upvotes: 6

Muhammad Rashid
Muhammad Rashid

Reputation: 5

The problem is that your presenting view controller name is VC instead of present. If you do vc(alert, animated: true, completion: nil) It will work.

Upvotes: -3

Related Questions