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
Swift 4 simply has UIApplication.shared.keyWindow
property, no casting necessary.
Note that iOS 13/iPadOS introduces UIScenes
and explicit support for multiple windows, and thus deprecates the concept of keyWindow
as it is no longer valid.
This question has an overview how to get access to scene based windows.