Created
July 22, 2018 20:01
-
-
Save maxmzd/3da3248da0c6e43a8268d96fba06f6f7 to your computer and use it in GitHub Desktop.
Completion Handler Example 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
var src: String = "" | |
var completionHandler: ((_ success: Bool, _ outputURL: URL?)->())? | |
var outputURL: URL? | |
init(src: String, completion: ((_ success: Bool, _ outputURL: URL?) -> Void)? = nil) { | |
super.init() | |
self.src = src | |
self.completionHandler = completion | |
} | |
func finished(completed: Bool) { | |
if completed { | |
completionHandler!(true, outputURL) | |
} else { | |
completionHandler?(false, nil) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment