Skip to content

Instantly share code, notes, and snippets.

@alecthomas
Created November 10, 2014 00:31
Show Gist options
  • Save alecthomas/e69e8f4175042060ba1b to your computer and use it in GitHub Desktop.
Save alecthomas/e69e8f4175042060ba1b to your computer and use it in GitHub Desktop.
Convenient little Swift GCD dispatch_sync() variant that returns a value
public func dispatch_sync_result<T>(q: dispatch_queue_t, block: () -> T) -> T {
var r: T?
dispatch_sync(q, {
r = block()
})
return r!
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment