I want to create different layouts using size classes and I followed this example: https://www.hackingwithswift.com/quick-start/swiftui/how-to-create-different-layouts-using-size-classes
I extended the Xcode Master/Detail template and changed the ContentView as follows, with the two size classes and then using the horizontal size class to set a size class dependent navigation title. The problem is the navigation title would always read as "Compact". What am I missing here?
struct ContentView: View {
@Environment(\.managedObjectContext)
var viewContext
@Environment(\.verticalSizeClass) var vSizeClass
@Environment(\.horizontalSizeClass) var hSizeClass
var body: some View {
NavigationView {
MasterView()
.navigationBarTitle(Text(hSizeClass == .compact ? "Compact" : "Regular"))
.navigationBarItems(
leading: EditButton(),
trailing: Button(
action: {
withAnimation { Event.create(in: self.viewContext) }
}
) {
Image(systemName: "plus")
}
)
Text("Detail view content goes here")
.navigationBarTitle(Text("Detail"))
}.navigationViewStyle(DoubleColumnNavigationViewStyle())
}
}