Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Swift result type
enum Result<T, ErrorType> {
case success(T)
case error(ErrorType)
}
enum MyError: ErrorType {
case itFuckedUp
}
// no longer need unused parameters in completion blocks:
func doSomething(completionHandler: () -> (Result<String, NSError>)) {
if itWorks {
completionHandler(.success("it worked"))
} else {
completionHandler(.error(.itFuckedUp))
}
}
doSomething { result in
switch(result) {
case .success(let result) {
}
case .error(let error) {
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.