This is a companion discussion topic for the original entry at https://www.raywenderlich.com/1940309-advanced-swift-values-and-references/lessons/4
This is a companion discussion topic for the original entry at https://www.raywenderlich.com/1940309-advanced-swift-values-and-references/lessons/4
you said in all the 6 steps, “didSet” of pointValues is called , but its not getting called when you did “pv1.x = 50” . Since the array(pointValues) contains the copy of pv1, “didSet” shouldn’t get called when we mutate pv1. Isn’t that the correct behaviour ?
Hi! Thanks. Yes, I think you caught me in a misspeak. Oops. As you correctly surmised, pv1 is an independent copy outside of the array so array’s didSet doesn’t get called. The point that I was trying to (inarticulately) make is that if you dive into the array with a subscript and modify a value, did set gets trigger where this doesn’t happen with reference types inside the value typed array. There is no detection of the element mutation.
Thanks for the correction!