Re: [swift-users] struct property changing calls didSet of the Struct each time, but class won't

2017-11-13 Thread Guillaume Lessard via swift-users
In your example, when `Foo` is a class, then `A` does not see a mutation since the storage is out-of-line. When `Foo` is a struct, it is stored in-line and a mutation does mutate `A`. In other words, when what’s stored in `A` is a reference, the reference itself does not get mutated when you mu

Re: [swift-users] struct property changing calls didSet of the Struct each time, but class won't

2017-11-13 Thread Tino Heth via swift-users
> My code depends on the class version didSet but I used the struct version. It > took me a long time to debug this out. Is this a knowledge that has been well > known already? Yes, that’s how it’s supposed to be. It’s a feature of struct which isn’t available with classes (so considering the O

[swift-users] struct property changing calls didSet of the Struct each time, but class won't

2017-11-13 Thread Zhao Xin via swift-users
Hi everyone, See below codes, //: Playground - noun: a place where people can play import Foundation struct Foo { var bar = 0 } class A { var foo = Foo() { didSet { print("foo changed") } } } let a = A() for i in 1...5 { a.foo.bar = i