Replies: 2 comments 2 replies
-
I'm running into the same issue where I get
Also, using the computed @Model
final class Note { ... }
extension Note {
var taggedID: Tagged<Note, UUID> { .init(id) }
public typealias Id = Tagged<Note, UUID>
} As expected, SwiftData doesn't complain when using Tagged ID on Codable data! enum NoteContent: Codable, Identifiable, Equatable { ... }
extension NoteContent {
var id: Id { ... }
typealias Id = Tagged<NoteContent, String>
} |
Beta Was this translation helpful? Give feedback.
-
Hi @bradhowes and @Aayush9029, I don't believe you can just stick any kind of data into a Swift Data model. It has to be a subset of types that Swift Data / Core Data understands. Have either of you tried using value transformers to turn a |
Beta Was this translation helpful? Give feedback.
-
I added an attribute to a SwiftData model that had a
Tagged
type with a raw type ofInt
. Everything compiled fine but during a context save, there is a sigabrt raised inTagged.init(from decoder: Decoder)
(line 74) with a log message "Could not cast value of type '__NSDictionaryM' (0x14402f3b8) to 'NSNumber' (0x1eae3f340)."Here is my test model:
And here is a simple test case that raises the error:
As a work-around for now, I'm saving the raw value and and exposing a computed property that returns a proper
Tagged
value.Beta Was this translation helpful? Give feedback.
All reactions