This provided the clue to fix this error for me. For me, this appeared when I moved from iOS 17.7 to iOS18.0.
To be more specific, I had a main class with something like
@Model
final public class MainThing {
@Attribute(.unique) public var id : UUID
var name: String
@Relationship(deleteRule: .cascade) var things = [Thing]()
...
and Thing was simply
@Model
public class Thing {
var when: Date
var note: String
...
}
Changing these to the following:
@Model
final public class MainThing {
@Attribute(.unique) public var id : UUID
var name: String
@Relationship(deleteRule: .cascade, inverse: \Thing.mainThing) var things = [Thing]()
...
and Thing was simply
@Model
public class Thing {
var mainThing: MainThing?
var when: Date
var note: String
...
}
and setting the mainThing to the "one" being added to before adding the Thing fixed the problem.