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.
Nov ’25
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
Dec ’25
Reply to Persisting User Settings with SwiftData
I would wrap the UserSettings type inside an observable class and then use that class as an environment value @Environment(SettingsManager.self) var settingsManager Then this manager object could be made to handle all loading, updating and saving of the UserSettings object internally to have only one single source of truth.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’26
Reply to Data Persistence not functioning upon refresh
Unrelated perhaps but why are you even using SwiftData for this, wouldn't it be better to use a CSV (or JSON) file for persisting your data? Maybe I am misreading the code but to me it looks like you only want to store a single instance of your model and then I believe SwiftData or any other database solution is overkill and that a simple file is more suitable.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Feb ’26
Reply to Swift Data Recovery
First of all you should check the console and check if you get any warning messages when you run the app and access your data. if nothing shows up then you can turn on sql debug logging to help you figure out what is happening. See this article from the Hacking With Swift website on how to do that, https://www.hackingwithswift.com/quick-start/swiftdata/using-launch-arguments-to-debug-swiftdata-and-core-data
Mar ’26
Reply to SwiftData Migration: Why no explicit ETL?
And we are just supposed to know what ETL means?
Replies
Boosts
Views
Activity
Nov ’25
Reply to How to correctly fetch data using SwiftData
I find the question a bit confusing. Firstly, are you talking about saving and fetching objects in general or is it the specific image property of type Data you mean when you write “data” in the question? Secondly it’s very hard to understand the last segment of code.
Topic: UI Frameworks SubTopic: General Tags:
Replies
Boosts
Views
Activity
Nov ’25
Reply to How to correctly fetch data using SwiftData
Do you get any error message in the console when you save? Could you replace try? with try when saving to see if any error is thrown do { try modelContext.save() } catch { print(error) } How is your model container declared and used?
Topic: UI Frameworks SubTopic: General Tags:
Replies
Boosts
Views
Activity
Nov ’25
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.
Replies
Boosts
Views
Activity
Nov ’25
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
Replies
Boosts
Views
Activity
Dec ’25
Reply to Persisting User Settings with SwiftData
I would wrap the UserSettings type inside an observable class and then use that class as an environment value @Environment(SettingsManager.self) var settingsManager Then this manager object could be made to handle all loading, updating and saving of the UserSettings object internally to have only one single source of truth.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jan ’26
Reply to Data Persistence not functioning upon refresh
Unrelated perhaps but why are you even using SwiftData for this, wouldn't it be better to use a CSV (or JSON) file for persisting your data? Maybe I am misreading the code but to me it looks like you only want to store a single instance of your model and then I believe SwiftData or any other database solution is overkill and that a simple file is more suitable.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Feb ’26
Reply to Swift Data Recovery
First of all you should check the console and check if you get any warning messages when you run the app and access your data. if nothing shows up then you can turn on sql debug logging to help you figure out what is happening. See this article from the Hacking With Swift website on how to do that, https://www.hackingwithswift.com/quick-start/swiftdata/using-launch-arguments-to-debug-swiftdata-and-core-data
Replies
Boosts
Views
Activity
Mar ’26
Reply to SwiftData ModelContext Pollution with Multiple ModelContainers and Schemas
Does it crash when you run the app or is it only the tests that crashes?
Replies
Boosts
Views
Activity
Mar ’26