Reputation: 1208
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
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
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