Skip to content

Instantly share code, notes, and snippets.

@SerggioC
Created May 17, 2020 21:19
Show Gist options
  • Save SerggioC/421aea80b8b092bdbcb5a145d6d566fd to your computer and use it in GitHub Desktop.
Save SerggioC/421aea80b8b092bdbcb5a145d6d566fd to your computer and use it in GitHub Desktop.
Access the window object from SceneDelegate or AppDelegate
func getCurrentWindow() -> UIWindow? {
if #available(iOS 13.0, *) {
if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
let sceneDelegate = windowScene.delegate as? SceneDelegate {
return sceneDelegate.window
} else {
return nil
}
} else {
// Fallback on earlier versions
return self.window
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment