Created
July 5, 2018 11:47
-
-
Save Alex-Ozun/433d8fc11d75c486aa00f103182446f8 to your computer and use it in GitHub Desktop.
synchronized accessor in Swift
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
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