I'm trying to make my swiftUI view resize dynamically. I see that the way to do this is to use the environment info like below:
@Environment(\.horizontalSizeClass) var sizeClass
However, it does not seem to return anything. When using the debugger, I see that the variable is set to 'nil'. What am I doing wrong? Do I need to enable an option or something in info.plist for example?
My code is pretty basic:
struct ContentView: View {
@Environment(\.horizontalSizeClass) var sizeClass
var body: some View {
if self.sizeClass == .compact {
Home_Vertical()
}
else {
Home_Horizontal()
}
}
}
I'm developing for iPhone and allowed all device orientations. The iOS deployment target is iOS 14.0 and xCode's version is 12.3.