Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is MyViewController in the window hierarchy?

Is there a way to check if MyViewController is in the window hierarchy ? I want to know if I can present an UIAlertController from it :

var alert = UIAlertController(title: "Hello", message: "Just for fun", preferredStyle: UIAlertControllerStyle.Alert)
MyViewController.presentViewController(alert, animated: true, completion: nil)
like image 492
Cherif Avatar asked Dec 19 '22 02:12

Cherif


1 Answers

The view controller's view will have its window property set if its in the hierarchy

if MyViewController.view.window != nil {
    // In the window hierarchy
}
like image 86
dan Avatar answered Dec 29 '22 14:12

dan