Post

Replies

Boosts

Views

Activity

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 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 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 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 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 Picker using SwiftData
The selection parameter for the picker should be a single item and not an array @State private var contractType: TypeOfContract = // some default type also the type of the value passed to .tag() must be the same type as the property above. So this issue is not so much about SwiftData but instead understanding how a picker works.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’25
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
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 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 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 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 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 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 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 SwiftData Migration: Why no explicit ETL?
And we are just supposed to know what ETL means?
Replies
Boosts
Views
Activity
Nov ’25
Reply to SwiftData: Crash when deleting from model, but only in prod
What do you mean with "more verbose way"? It seems to be the same command but one is wrapped in a generic function.
Replies
Boosts
Views
Activity
Oct ’25
Reply to Present User an error message when SwiftData save fails
Here is a good Apple tutorial on handling errors in a view.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Oct ’25
Reply to Swiftui Picker with optional value selected in picker
You should read the answers to your previous question carefully and also see this question on stackoverflow.com on using optionals with a picker
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Oct ’25
Reply to Picker using SwiftData
The selection parameter for the picker should be a single item and not an array @State private var contractType: TypeOfContract = // some default type also the type of the value passed to .tag() must be the same type as the property above. So this issue is not so much about SwiftData but instead understanding how a picker works.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Oct ’25
Reply to SwiftData: Unexpected backing data for snapshot creation
My guess is that a view is trying to access an instance of the object after it has been removed.
Replies
Boosts
Views
Activity
Oct ’25
Reply to Mutating an array of model objects that is a child of a model object
That’s a completely different issue and it’s not something you checked either in the code you have provided
Replies
Boosts
Views
Activity
Sep ’25