I’m getting this error:
Fatal error: 'try!' expression unexpectedly raised an error: SwiftData.SwiftDataError(_error: SwiftData.SwiftDataError._Error.loadIssueModelContainer)
I’m able to reproduce it in a new project this way:
- Use SwiftData
- Enable & select “My Mac (Designed for iPad)” as the run destination
- Add “iCloud” capability; select iCloud Documents, CloudKit & one Container
- Use a conditional inside the sheet
- Use
modelContext
inside the sheet
E.g.:
struct ContentView: View {
@Environment(.modelContext) private var modelContext
@State var showSheet = false
var body: some View {
Button {
showSheet = true
} label: {
Text("Show Sheet")
}
.sheet(isPresented: $showSheet) {
SheetView()
}
}
}
struct SheetView: View {
@Environment(.modelContext) private var modelContext
var body: some View {
if true { // <--- any conditional in the sheet is causing the crash
Text("Hello")
}
}
}