Skip to content

Instantly share code, notes, and snippets.

@Reflejo
Created January 15, 2015 21:10
Show Gist options
  • Save Reflejo/bed6809c86faa9af1b26 to your computer and use it in GitHub Desktop.
Save Reflejo/bed6809c86faa9af1b26 to your computer and use it in GitHub Desktop.
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
@Reflejo
Copy link
Author

Reflejo commented Jan 15, 2015

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment