Created
July 5, 2017 00:01
-
-
Save khanlou/e4b5db71a6a18903d8a78edd04068780 to your computer and use it in GitHub Desktop.
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
public struct NilError: Error, CustomStringConvertible { | |
let file: String | |
let line: Int | |
public init(file: String = #file, line: Int = #line) { | |
self.file = file | |
self.line = line | |
} | |
public var description: String { | |
return "Nil returned at " + (file) + ":\(line)" | |
} | |
} | |
extension Optional { | |
public func unwrap(file: String = #file, line: Int = #line) throws -> Wrapped { | |
guard let result = self else { | |
throw NilError(file: file, line: line) | |
} | |
return result | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment