MyViewController是否在窗口层次结构中?

Che*_*rif 4 uiviewcontroller ios swift

有没有办法检查是否MyViewController在窗口层次结构中?我想知道我是否可以提供一个UIAlertController:

var alert = UIAlertController(title: "Hello", message: "Just for fun", preferredStyle: UIAlertControllerStyle.Alert)
MyViewController.presentViewController(alert, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)

dan*_*dan 9

视图控制器viewwindow在层次结构中设置其属性

if MyViewController.view.window != nil {
    // In the window hierarchy
}
Run Code Online (Sandbox Code Playgroud)