Skip to content

Instantly share code, notes, and snippets.

@LovaRK
Last active April 5, 2021 05:11
Show Gist options
  • Save LovaRK/d9878dafd32ac966bec04e502e609c29 to your computer and use it in GitHub Desktop.
Save LovaRK/d9878dafd32ac966bec04e502e609c29 to your computer and use it in GitHub Desktop.
extension UIApplication {
var currentWindow: UIWindow? {
connectedScenes
.filter({$0.activationState == .foregroundActive})
.map({$0 as? UIWindowScene})
.compactMap({$0})
.first?.windows
.filter({$0.isKeyWindow}).first
}
}
// How to use
if let window = UIApplication.shared.currentWindow {
// do whatever you want with window
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment