Post

Replies

Boosts

Views

Activity

SwiftData: how to reference same model?
I have the following model: @Model class Person { var name = "" @Relationship(deleteRule: .nullify, inverse: \Person.ref) var ref: Person? = nil } Now consider the following code: let peter: Person let cristina: Person peter.ref = cristina modelContext.delete(cristina) I would expected that peter.ref is nil, because referenced person was deleted. In reality, this won't even compile due to this error: Circular reference resolving attached macro 'Relationship' If I remove 'inverse' from the relationship it will compile, but it does not do what I need then. So is it possible to have a reference on the model itself with nullify capability? PS Using Xcode 15 beta 7
1
0
826
Aug ’23