Post

Replies

Boosts

Views

Activity

Reply to ModelContext.model(for:) returns deleted objects
I'm writing some tests to confirm the behavior of my app, you are actually unit testing SwiftData and not your app. As for the problem, I am not sure it's a bug and that they deliberately keep the object in the ModelContext for a short while to avoid problems for the app using it. The following test would pass though #expect(result.isDeleted)
Topic: App & System Services SubTopic: iCloud Tags:
May ’25
Reply to SwiftData duplicates values inside array on insert()
I didn't notice Feature was a many-to-many relationship, I thought the array was owned by the Car/CarData object, my bad. There is really no point in making your models conform to Identifiable and have a custom id property since they already conform to this protocol (unless you have some specific reason to use your own identifier value). I have no idea if this could help with the duplicate Feature objects issue but maybe it could be worth trying by removing the id property and use the default one instead.
Topic: App & System Services SubTopic: iCloud Tags:
Mar ’25
Reply to Migrating a swiftData project to CloudKit to implement iCloudSync.
You could make the model properties private and rename them and then add computed properties with the old name that you can access from outside the class. var someString: String could be replaced with private var someStringStored: String? var someString: String { get { someStringStored ?? "" } set { someStringStored = newValue } }
Topic: App & System Services SubTopic: iCloud Tags:
Replies
Boosts
Views
Activity
May ’25
Reply to ModelContext.model(for:) returns deleted objects
I'm writing some tests to confirm the behavior of my app, you are actually unit testing SwiftData and not your app. As for the problem, I am not sure it's a bug and that they deliberately keep the object in the ModelContext for a short while to avoid problems for the app using it. The following test would pass though #expect(result.isDeleted)
Topic: App & System Services SubTopic: iCloud Tags:
Replies
Boosts
Views
Activity
May ’25
Reply to SwiftData crashes on fetchHistory
A crash and a thrown error are two completely different things and you can not replace a crash with a thrown error with the exception of if you are deliberately crashing by calling fatalError(_) but I very much doubt that is what is happening here.
Topic: App & System Services SubTopic: iCloud Tags:
Replies
Boosts
Views
Activity
Apr ’25
Reply to UserDefaults to SwifData Migration
if you’re asking if there’s an automatic way then no there isn’t but doing this should be pretty straightforward, check if the move has already been done when the app starts and if not load the data from UserDefaults and store it using your SwiftData models.
Topic: App & System Services SubTopic: iCloud Tags:
Replies
Boosts
Views
Activity
Mar ’25
Reply to SwiftData duplicates values inside array on insert()
I didn't notice Feature was a many-to-many relationship, I thought the array was owned by the Car/CarData object, my bad. There is really no point in making your models conform to Identifiable and have a custom id property since they already conform to this protocol (unless you have some specific reason to use your own identifier value). I have no idea if this could help with the duplicate Feature objects issue but maybe it could be worth trying by removing the id property and use the default one instead.
Topic: App & System Services SubTopic: iCloud Tags:
Replies
Boosts
Views
Activity
Mar ’25