How do I get the keyWindow reference in a swift app?

后端 未结 8 994
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-12 03:55

In Objective-C in the viewDidLoad method of a UIViewController I do this to get the keyWindow reference in my iOS app:

 UIWindow * keyWindow = [[UIApplication sh         


        
8条回答
  •  既然无缘
    2021-02-12 04:11

    The easiest way to do that is:

    in Objective-C

    [UIApplication sharedApplication].windows.firstObject
    

    in Swift

    UIApplication.shared.windows.first!
    

    Note that this works only if you do not support multiple windows.

提交回复
热议问题