Created
January 15, 2015 21:10
-
-
Save Reflejo/bed6809c86faa9af1b26 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Foo { | |
var bar: String = "" | |
} | |
class Something { | |
var foo: Foo = Foo() { | |
didSet { | |
println("didSet called") | |
} | |
} | |
} | |
var s = Something() | |
s.foo.bar = "?????" | |
s.foo.bar = "?????" | |
// stdout: | |
// didSet called | |
// didSet called |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If that's the expected behavior because a new copy of the struct is created then my question is: shouldn't one be able to modify a struct that is set as "var" on a class without replacing it?
Furthermore, I think that the fact the struct is copied, in this case, is an implementation detail that I don't think it should be carried to the didSet/willSet mechanism.
Thoughts?