Skip to content

Instantly share code, notes, and snippets.

@bdpdx
Created January 4, 2017 22:24
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 bdpdx/19a71303063b6a355bafbb6825d4021f to your computer and use it in GitHub Desktop.
Save bdpdx/19a71303063b6a355bafbb6825d4021f to your computer and use it in GitHub Desktop.
NSLocking synchronize() method that returns a value, Swift 3
extension NSLocking {
@discardableResult
func synchronize<T>(_ closure: (Void) -> T) -> T {
lock() ; defer { unlock() }
return closure()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment