Skip to content

Instantly share code, notes, and snippets.

@danielctull
Created June 8, 2014 20:16
Show Gist options
  • Save danielctull/70a69e09d7b108cc2589 to your computer and use it in GitHub Desktop.
Save danielctull/70a69e09d7b108cc2589 to your computer and use it in GitHub Desktop.
Error return in Switch using enumeration and associated error value
import Cocoa
enum Result {
case Success
case Failure(NSError)
}
func DoTask() -> Result {
return .Failure(NSError.errorWithDomain("Domain", code: 4, userInfo:nil))
}
let result = DoTask()
switch result {
case let .Failure(error):
println(error)
case .Success:
println("Success")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment