Skip to content

Instantly share code, notes, and snippets.

@rjchatfield
Created October 13, 2019 12:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rjchatfield/ccf97aaa1b45dc8535b93ab7e92ad285 to your computer and use it in GitHub Desktop.
Save rjchatfield/ccf97aaa1b45dc8535b93ab7e92ad285 to your computer and use it in GitHub Desktop.
inout Mutation
func doNothing(_: inout String) { /* do nothing!! */ }
var value = "foo" {
didSet { print("didSet") }
}
doNothing(&value) // Unfortunately, triggers didSet!
var proxy: String {
get { value }
set { value = newValue }
}
doNothing(&proxy) // Unfortunately, triggers didSet!
var proxy2: String {
_read { yield value }
_modify {
var temp = value
yield &temp
value = temp
}
}
doNothing(&proxy2) // Unfortunately, triggers didSet!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment