Skip to content

Instantly share code, notes, and snippets.

@Alex-Ozun
Created July 5, 2018 11:47
Show Gist options
  • Save Alex-Ozun/433d8fc11d75c486aa00f103182446f8 to your computer and use it in GitHub Desktop.
Save Alex-Ozun/433d8fc11d75c486aa00f103182446f8 to your computer and use it in GitHub Desktop.
synchronized accessor in Swift
func synchronized<T>(_ object: Any, block: () -> T) -> T {
objc_sync_enter(object)
let result = block()
objc_sync_exit(object)
return result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment