Suppose I have class ExerciseSet with 3 properties: id, name, isEnabled.
I have an array of objects of this class:
var exerciseSets: [ExerciseSet] = [] {
didSet {
ExerciseSet.syncWithPList(updatedSets: exerciseSets)
}
}
Somewhere in the code I do the following:
exerciseSets[index].isEnabled = !exerciseSets[index].isEnabled
But didSet would not fire in this case. Only if I write like this:
let set = exerciseSets[index]
set.isEnabled = !set.isEnabled
exerciseSets[index] = set
Why is it so? Can I somehow use the former option? The latter one seems to verbose, I hate it.