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
Topic: App & System Services SubTopic: iCloud Tags:
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
Topic: App & System Services SubTopic: iCloud Tags:
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.
Topic: App & System Services SubTopic: iCloud Tags:
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 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
Topic: App & System Services SubTopic: iCloud Tags:
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
Topic: App & System Services SubTopic: iCloud Tags:
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.
Topic: App & System Services SubTopic: iCloud 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 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