Post

Replies

Boosts

Views

Activity

Reply to SwiftData - Context missing for optional
I'm seeing the same crash after updating iPhone to iOS18. It doesn't crash the sim, which is iOS17 for me. Also a very weird thing is that if I don't call saveContext() is don't crash (but the context does seem to update and look like the record is deleted??). Thankfully I haven't released app to prod yet. This is quite worrying. I've spent a lot time trying different way of passing in a context. This doesn't happen on iOS 17. this seem to work in my delete function, but shouldn't I have to save the context? container.mainContext.delete(recording) // saveContext() SwiftData/BackingData.swift:251: Fatal error: Context is missing for Optional(SwiftData.PersistentIdentifier(id: SwiftData.PersistentIdentifier.ID(url: x-coredata://2B4AE978-7D52-4789-A52A-4593CEBF5690/Recording/p27), implementation: SwiftData.PersistentIdentifierImplementation))
Sep ’24
Reply to SwiftData - Context missing for optional
I have found a solution, at least one that works for my project. I hope it can help others here! The issue wasn't in the code I had to delete the record from the model context. The problem was an improper use of Binding. A parent view was presenting a list of child views. Into that child view I was passing a "Recording". Within the child that Recording was an at Binding. That was totally unnecessary and I think causes a conflict with the model context being used by the child(?). So it was being passed in as a constant like this: List { ForEach(filteredRecordings) { recording in RecordingItemView( recording: .constant(recording), Removing the Binding and changing a regular property fixed my iOS18 crash: List { ForEach(filteredRecordings) { recording in RecordingItemView( recording: recording, The UI of my parent view is already being updated via changes to the modelContext... so the Binding is just a total mistake. Good luck!
Sep ’24