MyViewController 是否在 window 层次结构中?

Is MyViewController in the window hierarchy?

有没有办法检查 MyViewController 是否在 window 层次结构中? 我想知道我是否可以从中展示一个 UIAlertController :

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

视图控制器的 view 将设置 window 属性 如果它在层次结构中

if MyViewController.view.window != nil {
    // In the window hierarchy
}