Swift Model Container Error
1
2
3
4
5
6
7
8
9
static var sample: () throws -> ModelContainer = {
        let schema = Schema([Account.self, Monster.self])
        let configuration = ModelConfiguration(isStoredInMemoryOnly: true)
        let container = try ModelContainer(for: schema, configurations: [configuration])
        Task { @MainActor in
            Account.insertSampleData(modelContext: container.mainContext)
        }
        return container
    }
If didn’t specify correct model in Schema initializer:
1
Schema([Account.self, Monster.self])
There won’t be any exception, preview just crash.
 This post is licensed under  CC BY 4.0  by the author.