Post

Replies

Boosts

Views

Created

SwiftData self-referencing model has wierd behavior
I have a model like this: @Model final class TreeNodeModel{ var createdAt: Date var title: String var content: String //Relations @Relationship(deleteRule:.cascade) var children: [TreeNodeModel]? init(title:String,content:String = "",) { self.title = title self.content = content } } When I try to insert models like below (works well): let parent = TreeNodeModel(title: "parent") let child = TreeNodeModel(title: "child") parent.children!.append(child) modelContext.insert(parent) But if try to insert models like below (wierd things happened): not only parent has one children [child], child also has one children [parent] let parent = TreeNodeModel(title: "parent") modelContext.insert(parent) let child = TreeNodeModel(title: "child") parent.children!.append(child) This is quit wierd, anyone has met this kind of issue?
2
1
1.2k
Aug ’23
The current model reference and the next model reference cannot be equal.
is anyone facing the error, "The current model reference and the next model reference cannot be equal", when using SwiftData with migration and iCloud/CloudKit integration?
Replies
4
Boosts
1
Views
1.7k
Activity
Sep ’23
SwiftData self-referencing model has wierd behavior
I have a model like this: @Model final class TreeNodeModel{ var createdAt: Date var title: String var content: String //Relations @Relationship(deleteRule:.cascade) var children: [TreeNodeModel]? init(title:String,content:String = "",) { self.title = title self.content = content } } When I try to insert models like below (works well): let parent = TreeNodeModel(title: "parent") let child = TreeNodeModel(title: "child") parent.children!.append(child) modelContext.insert(parent) But if try to insert models like below (wierd things happened): not only parent has one children [child], child also has one children [parent] let parent = TreeNodeModel(title: "parent") modelContext.insert(parent) let child = TreeNodeModel(title: "child") parent.children!.append(child) This is quit wierd, anyone has met this kind of issue?
Replies
2
Boosts
1
Views
1.2k
Activity
Aug ’23