docs/docsets/Alamofire.docset/Contents/Resources/Documents/Extensions/Result.html
extension Result
`
success
`
Returns the associated value if the result is a success, nil otherwise.
Swift
var success: Success? { get }
`
failure
`
Returns the associated error value if the result is a failure, nil otherwise.
Swift
var failure: Failure? { get }
`
init(value:error:)
`
Initializes a Result from value or error. Returns .failure if the error is non-nil, .success otherwise.
Swift
init(value: Success, error: Failure?)
| value |
A value.
|
| error |
An Error.
|
`
tryMap(_:)
`
Evaluates the specified closure when the Result is a success, passing the unwrapped value as a parameter.
Use the tryMap method with a closure that may throw an error. For example:
let possibleData: Result<Data, Error> = .success(Data(...))
let possibleObject = possibleData.tryMap {
try JSONSerialization.jsonObject(with: $0)
}
Swift
func tryMap<NewSuccess>(_ transform: (Success) throws -> NewSuccess) -> Result<NewSuccess, Error>
| transform |
A closure that takes the success value of the instance.
|
A Result containing the result of the given closure. If this instance is a failure, returns the same failure.
`
tryMapError(_:)
`
Evaluates the specified closure when the Result is a failure, passing the unwrapped error as a parameter.
Use the tryMapError function with a closure that may throw an error. For example:
let possibleData: Result<Data, Error> = .success(Data(...))
let possibleObject = possibleData.tryMapError {
try someFailableFunction(taking: $0)
}
Swift
func tryMapError<NewFailure>(_ transform: (Failure) throws -> NewFailure) -> Result<Success, Error> where NewFailure : Error
| transform |
A throwing closure that takes the error of the instance.
|
A Result instance containing the result of the transform. If this instance is a success, returns the same success.