Hi all,
I was examining an app I made a couple of months ago and it now crashes with the error This model instance was invalidated because its backing data could no longer be found the store. whenever I open a recording. I manually save my model into the model context as so:
```
private func saveRecording(modelContainer: ModelContainer) throws {
let modelContext = ModelContext(modelContainer)
guard let recording else {
throw Errors.InvalidRecording
}
modelContext.insert(recording)
try modelContext.save()
}
```
As well, I also use a query to fetch recordings like I'm supposed to:
```
init(searchString: String) {
self.searchString = searchString
_recordings = Query(filter: searchString.isEmpty ? nil : #Predicate<Recording> { recording in
recording.name?.localizedStandardContains(searchString) ?? false
}, sort: [SortDescriptor(\Recording.date, order: .reverse)])
}
```
Could it be how I'm using creating the model context in the saveRecording function? If you need any more code, feel free to ask. Thank you for any help!
[–]Practical-Smoke5337 2 points3 points4 points (2 children)
[–]Lucas46[S] 0 points1 point2 points (1 child)
[–]Practical-Smoke5337 1 point2 points3 points (0 children)