Greetings. I'm trying to insert objects into the managed context but I'm getting a runtime error "Thread 1: Cannot insert 'MyClass' in this managed object context because it is not found in the associated managed object model.". The code to set things up is pretty much straight from Apple -
var sharedModelContainer: ModelContainer = {
let schema = Schema([
MyClass.self,
MyOtherClass.self
])
let modelConfiguration = ModelConfiguration(schema: schema, isStoredInMemoryOnly: false)
do {
return try ModelContainer(for: schema, configurations: [modelConfiguration])
} catch {
fatalError("Could not create ModelContainer: \(error)")
}
}()
The context is being accessed through the environment like so -
public final class MyAppLogic {
@Environment(\.modelContext) private var context
...
...
myClasses.forEach { myClass in
context.insert(myClass)
}
Any suggestions greatly appreciated.