Post

Replies

Boosts

Views

Activity

Reply to SwiftData nested custom model CRASH
Ok so two issues I can see here, forgive me if I'm wrong but I need to rush this answer First up you're not using Relationships @Model class AModel { @Attribute(.unique) var id:String var date:Date @Relationship(inverse: \BModel.aModel) var b:[BModel] } @Model class BModel { @Attribute(.unique) var id:String var date:Date var aModel: AModel? init() { self.id = UUID().uuidString self.date = Date() } } Secondly, and this is something that only started happening to me in the last two betas. I found I need to insert the bModel before appending it to a property in aModel. This may not be the issue, as usually this only affects me when passing a model through in an initialiser, but worth a shot .onAppear { let model = BModel() modelContext.insert(model) a.b.append(model) print(a.b) } Again, apologies if I misunderstood the question, I'm in a bit of a rush here. Let me know if I can help more
Aug ’23