Interesting new Swift keyword I learned about today: "nonmutating."
e.g. UnsafeMutablePointer's
var memory: T { get nonmutating set }
Conversation
I just discovered this myself. I'm using an enum to manage app defaults, and now I can…
AppDefault.Bounciness.intValue = 5
1
Yikes. What does that mean? Have a gist?
1
1
1
Replying to
Yes. :)
That setter *is* mutating. This will break compilation semantics.
Replying to
Hah! That's fair. I'd consider it nonmutating, though, because it doesn't change the instance itself, just global state. No?
1
Hm. I think you’re right, actually!
1
Replying to
ah, or do you mean that the compiler might not realize that the value of that property depends on external state?
Replying to
the semantics are the same as your UnsafeMutablePointer example: the content of the pointed-too memory could change too.)

