Last active
July 1, 2021 08:49
-
-
Save jimmyhoran/d562df99bc45997e8b78589d3d1b8e9f to your computer and use it in GitHub Desktop.
Safe access to the `keyWindow` for iOS 13+ support of multiple UIScene
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let keyWindow = UIApplication.shared.connectedScenes | |
.filter { $0.activationState == .foregroundActive } | |
.map { $0 as? UIWindowScene } | |
.compactMap { $0 } | |
.first?.windows | |
.filter { $0.isKeyWindow } | |
.first | |
// Usage e.g. | |
_ = keyWindow?.safeAreaInsets.bottom ?? 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment