'SwiftUI - 'windows' was deprecated in iOS 15.0: Use UIWindowScene.windows
I'm having the following code block:
struct StackOverflow: View {
var body: some View {
Text("Hello, World!")
.padding(.bottom,UIApplication.shared.windows.first?.safeAreaInsets.bottom ?? 15)
}
}
However, this returns the following error:
'windows' was deprecated in iOS 15.0: Use UIWindowScene.windows on a relevant window scene instead
I tried to utilize UIWindowScene.windows but it's not working somehow. Any ideas how to translate this into the new syntax?
Solution 1:[1]
struct StackOverflow: View {
var body: some View {
let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene
let window = windowScene?.windows.first
Text("Hello, World!")
.padding(.bottom, window?.safeAreaInsets.bottom ?? 15)
}
}
Depends on what you need, there's more about this here:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
