Post

Replies

Boosts

Views

Activity

Reply to SwiftData: This model instance was invalidated because its backing data could no longer be found the store
When you are using @ModelActor you have access to a specific model context for that actor via the property modelContext so you should have try modelContext.delete(… and you should definitely not use the context from the main actor in any other actor. This alone will probably not fix the crash since you have a reference to the deleted objects in self._rooms that you need to clear before doing the delete.
3w
Reply to SwiftData .autosaveEnabled / rollback() trouble
One option is to create and work with a local instance of ModelContext in your view and then call save() or rollback (or simply discard it) on that local instance. Once you call save the changes will be propagated to the main context. One article about this can be found on https://www.hackingwithswift.com/quick-start/swiftdata/how-to-discard-changes-to-a-swiftdata-object or as part of this longer article, https://medium.com/@matgnt/the-art-of-swiftdata-in-2025-from-scattered-pieces-to-a-masterpiece-1fd0cefd8d87
1d