Last active
February 6, 2016 17:56
-
-
Save naoty/8aa119d6974c2e16a821 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
extension ErrorType { | |
var errorSummary: String { | |
return "" | |
} | |
} | |
extension NSError { | |
var errorSummary: String { | |
return localizedDescription | |
} | |
} | |
let error: ErrorType = NSError(domain: "com.github.naoty.playground", code: 1000, userInfo: [NSLocalizedDescriptionKey: "Something wrong"]) | |
print(error.errorSummary) //=> "\n" |
This file contains hidden or 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
protocol FriendlyErrorType: ErrorType { | |
var errorSummary: String { get } | |
} | |
extension NSError: FriendlyErrorType { | |
var errorSummary: String { | |
return localizedDescription | |
} | |
} | |
let error: FriendlyErrorType = NSError(domain: "com.github.naoty.playground", code: 1000, userInfo: [NSLocalizedDescriptionKey: "Something wrong"]) | |
print(error.errorSummary) //=> "Something wrong\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment