Hi there, I have a crash when i use live mode, for rate a title with Picker.
And It not save rate variable using the following code in my Staging view, and BookModel
Staging view
Text("Rate \(book.title)")
Picker ("Rate this", selection: $selectedRate) {
Text("1").tag(1)
Text("2").tag(2)
Text("3").tag(3)
Text("4").tag(4)
Text("5").tag(5)
}
.pickerStyle(SegmentedPickerStyle())
.onChange(of: selectedRate, perform: { value in
model.updateRating(forId: book.id, rating: selectedRate)
})
BookModel
func updateRating(forId: Int, rating: Int) {
if let index = books.firstIndex(where: { $0.id == forId }) {
books[index].rating = rating
}
}
Any helps? I debug, it, and I think in the view model reload the data. But for me, it the same code like the solution. I try to put together model and data equal to solution, but app crash too.
Thanks!