I am experiencing the exact same problem with the current iOS/Xcode version. The issue occurs intermittently but completely breaks the database. It appears that the data is not always saved correctly, and attempting to load it subsequently leads to an exception. In my network measurement app, I attempt to store the results using SwiftData. I have tried disabling autosave and saving the context manually, but the problem persists. Additionally, I tried removing the @Attribute(.unique) from my UUID field, but this does not seem to resolve the issue.
This is my model:
@Model
internal class StorageModel {
var uuid: UUID
var date: Date
var result: ResultModel
required init(uuid: UUID = UUID(), date: Date = Date(), result: ResultModel = .init()) {
self.uuid = uuid
self.date = date
self.result = result
}
}