Result
public enum Result<T, Error> : CustomStringConvertible, CustomDebugStringConvertible where Error : Error
An enum representing either a failure with an explanatory error, or a success with a result value.
-
Undocumented
Declaration
Swift
case success(T) -
Undocumented
Declaration
Swift
case failure(Error)
-
Constructs a success wrapping a
value.Declaration
Swift
public init(value: T) -
Constructs a failure wrapping an
error.Declaration
Swift
public init(error: Error) -
Constructs a result from an
OptionalValue, failing withErrorifnil.Declaration
Swift
public init(_ value: T?, failWith: @autoclosure () -> Error) -
Constructs a result from a function that uses
throw, failing withErrorif throws.Declaration
Swift
public init(_ function: @autoclosure () throws -> T) -
Constructs a result from a function that uses
throw, failing withErrorif throws.Declaration
Swift
public init(attempt function: () throws -> T)
-
Returns the value from
successResults orthrows the error.Declaration
Swift
public func dematerialize() throws -> T -
Case analysis for Result.
Returns the value produced by applying
ifFailuretofailureResults, orifSuccesstosuccessResults.Declaration
Swift
public func analysis<Result>(ifSuccess: (T) -> Result, ifFailure: (Error) -> Result) -> Result
-
The domain for errors constructed by Result.
Declaration
Swift
public static var errorDomain: String { get } -
The userInfo key for source functions in errors constructed by Result.
Declaration
Swift
public static var functionKey: String { get } -
The userInfo key for source file paths in errors constructed by Result.
Declaration
Swift
public static var fileKey: String { get } -
The userInfo key for source file line numbers in errors constructed by Result.
Declaration
Swift
public static var lineKey: String { get } -
Constructs an error.
Declaration
Swift
public static func error(_ message: String? = nil, function: String = #function, file: String = #file, line: Int = #line) -> NSError
-
Declaration
Swift
public var description: String { get }
-
Declaration
Swift
public var debugDescription: String { get }
View on GitHub
Result Enumeration Reference