>     init(keysAndValues:Dictionary<String, String>) {
>         self.keys.append(contentsOf: keysAndValues.keys)
>     }

> 
> Above code doesn't call `didSet` in playground. My .swift file is similar and 
> didn't call `didSet` either. However, if without a struct, `didSet` is called.

“If you don’t need to compute the property but still need to provide code that 
is run before and after setting a new value, use willSet and didSet. The code 
you provide is run any time the value changes outside of an initializer.”

Excerpt From: Apple Inc. “The Swift Programming Language (Swift 3.1).” iBooks. 
https://itun.es/us/jEUH0.l

Note “outside of an initializer”.  didSet and willSet are not called in 
initializers.



_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

Reply via email to