Post

Replies

Boosts

Views

Activity

Is property `id` forbidden for @Model?
I'm currently working on SwiftData, and having trouble with id properties. I was constantly getting this error with my @Model. error: Row (pk = 1) for entity 'AnalyzedMessage' is missing mandatory text data for property 'id' Timestamp: 2024-05-31 14:13:24.483647+09:00 | Library: CoreData | Subsystem: com.apple.coredata | Category: error \ @Model final class AnalyzedMessage { var id: String var user: User var createdAt: Date var text: String var attachments: [Attachment] var recording: Recording? var replyMessage: ReplyMessage? } As I remove all properties named id (including custom Value types), error just disappeared and app works as I intended with no issue . @Model final class AnalyzedMessage { var messageID: String var user: User var createdAt: Date var text: String var recording: Recording? } I thought using property named id causes problem only when fetching some data like this: context.model(for: myModel.id). So, is property id taken by @Model and forbidden to use? If so, I think there should be a safe-guard for miss-usage just like in my case. +) However, lots of open-source libraries use property id for their models. Do we have to handle all of these models to bypass not to use it? I think it's pretty disturbing..
0
0
466
May ’24