I have two one-to-many models and I'm getting an unexplained crash when trying to access the relationship properties of the models.
The reason for the error is as follows:
Thread 1: EXC_BREAKPOINT (code=1, subcode=0x1038f4448)
Xcode shows that the error occurs in the model's .getValue(for: .rows) method.
This is my SwiftData model and other code:
@Model class Row {
var section: Section?
init(section: Section? = nil) {
self.section = section
}
init() {
self.section = nil
}
}
@Model class Section {
@Relationship(.cascade, inverse: \Row.section)
var rows: [Row] = []
init(rows: [Row]) {
self.rows = rows
}
}
class ViewController: UIViewController {
var container: ModelContainer?
override func viewDidLoad() {
super.viewDidLoad()
do {
container = try ModelContainer(for: [Section.self, Row.self])
} catch {
print(error)
}
let row = Row()
let section = Section(rows: [row])
section.rows.append(row)
var myRows = section.rows //Accessing relationship properties causes crash
print("hello") //no print
}
}
If I access the relationship property of the model, the program crashes. Such as passing to a variable.
var myRows = section.rows
Or just printing the relationship property of the model also crashes.
print(section.rows)
Xcode 15 beta 4 and 5.
Post
Replies
Boosts
Views
Activity
I am a student from a non-English speaking country. I would like to get the sample code from the "Make apps smarter with Natural Language" keynote on dynamic word embeddings and custom sentence embeddings. I can't find relevant examples on google to keep learning about it. I hope the developer community can share the full text of the sample code for the Nosh app and Merch app in the video. Thanks Vivek and Doug.
I am a student from a non-English speaking country. I would like to get the sample code from the "Make apps smarter with Natural Language" keynote on dynamic word embeddings and custom sentence embeddings. I can't find relevant examples on google to keep learning about it. I hope the developer community can share the full text of the sample code for the Nosh app and Merch app in the video. Thanks Vivek and Doug.