Skip to content

Commit

Permalink
Merge pull request #48 from ikesyo/error-with-message
Browse files Browse the repository at this point in the history
Add an optional message parameter for NSLocalizedDescriptionKey to Result.static.error()
  • Loading branch information
robrix committed May 22, 2015
2 parents 437062f + 7189cd3 commit 7fec10d
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions Result/Result.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,18 @@ public enum Result<T, Error>: Printable, DebugPrintable {
public static var lineKey: String { return "\(errorDomain).line" }

/// Constructs an error.
public static func error(function: String = __FUNCTION__, file: String = __FILE__, line: Int = __LINE__) -> NSError {
return NSError(domain: "com.antitypical.Result", code: 0, userInfo: [
public static func error(message: String? = nil, function: String = __FUNCTION__, file: String = __FILE__, line: Int = __LINE__) -> NSError {
var userInfo: [String: AnyObject] = [
functionKey: function,
fileKey: file,
lineKey: line,
])
]

if let message = message {
userInfo[NSLocalizedDescriptionKey] = message
}

return NSError(domain: errorDomain, code: 0, userInfo: userInfo)
}


Expand Down

0 comments on commit 7fec10d

Please sign in to comment.