Created
January 4, 2017 22:24
-
-
Save bdpdx/19a71303063b6a355bafbb6825d4021f to your computer and use it in GitHub Desktop.
NSLocking synchronize() method that returns a value, Swift 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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