Skip to content

Instantly share code, notes, and snippets.

@serhiybutz
Created September 20, 2021 19:14
Show Gist options
  • Save serhiybutz/5024131300861dc2e47f33d8ea17a703 to your computer and use it in GitHub Desktop.
Save serhiybutz/5024131300861dc2e47f33d8ea17a703 to your computer and use it in GitHub Desktop.
class Foo {
let sharedCounter = Shared(value: 0)
let sharedName = Shared(value: "")
let sm = SharedManager()
func reset() {
sm.borrow(sharedCounter, sharedName) { sharedCounter, sharedName in
sharedCounter.value = 0
sharedName.value = ""
}
}
func setName(_ name: String) {
sm.borrow(sharedName) { sharedName in
sharedName.value = name
}
}
func incFoo() {
sm.borrow(sharedCounter) { sharedCounter in
sharedCounter.value += 1
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment