Advanced Swift: Values and References 路 Mutation of self | raywenderlich.com


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, 鈥渄idSet鈥 of pointValues is called , but its not getting called when you did 鈥減v1.x = 50鈥 . Since the array(pointValues) contains the copy of pv1, 鈥渄idSet鈥 shouldn鈥檛 get called when we mutate pv1. Isn鈥檛 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鈥檚 didSet doesn鈥檛 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鈥檛 happen with reference types inside the value typed array. There is no detection of the element mutation.

Thanks for the correction!

Thank you so much for the reply @rayfix