Hey all,
could you pls help me to understand how existing items are saved in the var items: [ChecklistItem] array after they were edited?
The delegate method in CheckListViewController is
func addItemViewController(_ controller: AddItemViewController, didFinishEditing item: ChecklistItem) {
if let index = items.index(of: item) {
let indexPath = IndexPath(row: index, section: 0)
if let cell = tableView.cellForRow(at: indexPath) {
configureText(for: cell, with: item)
}
}
dismiss(animated: true, completion: nil)
}
I understand that you find the “equal” object in the items array, but where do you write the edited item in items[]?
For example you had first “Walk the dog” → Edited it to “Walk the cat”. If you scroll cell for rowAtIndexPath is triggered and this method looks in the items array and should read “Walk the dog”, because you never wrote to this array?
I looked up the Swift Standard Library for index(of: )
var students = [“Ben”, “Ivy”, “Jordell”, “Maxime”]
if let i = students.index(of: “Maxime”) {
students[i] = “Max”
}
print(students)
// Prints “[“Ben”, “Ivy”, “Jordell”, “Max”]”
and there they rewrite the value in the students array.
I can’t find it in our code. Has it to do something with tag?
Thanks in advance