How do I return from the function after checking a condition inside Swift closure? Return from Swift closure just returns from the closure, not the function. Specifically, I am using the following emulation of @synchronized in Swift:
func synchronized(_ object: AnyObject, block: () -> Void) {
objc_sync_enter(object)
block()
objc_sync_exit(object)
}
func synchronized<T>(_ object: AnyObject, block: () -> T) -> T {
objc_sync_enter(object)
let result: T = block()
objc_sync_exit(object)
return result
}
And then inside my function:
public func stopRunning() {
synchronized( self ) {
if status != .finished {
return;//<--Need to return from the function here, not just closure
}
}
...
...
}