-
Notifications
You must be signed in to change notification settings - Fork 1
DownloadResponse
Used to store all data associated with a serialized response of a download request.
public struct DownloadResponse<Success, Failure: Error>
CustomDebugStringConvertible
, CustomStringConvertible
Creates a DownloadResponse
instance with the specified parameters derived from response serialization.
public init(request: URLRequest?, response: HTTPURLResponse?, fileURL: URL?, resumeData: Data?, metrics: URLSessionTaskMetrics?, serializationDuration: TimeInterval, result: Result<Success, Failure>)
- request: The
URLRequest
sent to the server. - response: The
HTTPURLResponse
from the server. - temporaryURL: The temporary destination
URL
of the data returned from the server. - destinationURL: The final destination
URL
of the data returned from the server, if it was moved. - resumeData: The resume
Data
generated if the request was cancelled. - metrics: The
URLSessionTaskMetrics
of theDownloadRequest
. - serializationDuration: The duration taken by serialization.
- result: The
Result
of response serialization.
The URL request sent to the server.
let request: URLRequest?
The server's response to the URL request.
let response: HTTPURLResponse?
The final destination URL of the data returned from the server after it is moved.
let fileURL: URL?
The resume data generated if the request was cancelled.
let resumeData: Data?
The final metrics of the response.
let metrics: URLSessionTaskMetrics?
The time taken to serialize the response.
let serializationDuration: TimeInterval
The result of response serialization.
let result: Result<Success, Failure>
Returns the associated value of the result if it is a success, nil
otherwise.
var value: Success?
Returns the associated error value if the result if it is a failure, nil
otherwise.
var error: Failure?
The textual representation used when written to an output stream, which includes whether the result was a success or failure.
var description: String
The debug textual representation used when written to an output stream, which includes the URL request, the URL response, the temporary and destination URLs, the resume data, the durations of the network and serialization actions, and the response serialization result.
var debugDescription: String
Evaluates the given closure when the result of this DownloadResponse
is a success, passing the unwrapped
result value as a parameter.
public func map<NewSuccess>(_ transform: (Success) -> NewSuccess) -> DownloadResponse<NewSuccess, Failure>
Use the map
method with a closure that does not throw. For example:
let possibleData: DownloadResponse<Data> = ...
let possibleInt = possibleData.map { $0.count }
- transform: A closure that takes the success value of the instance's result.
A DownloadResponse
whose result wraps the value returned by the given closure. If this instance's result is a failure, returns a response wrapping the same failure.
Evaluates the given closure when the result of this DownloadResponse
is a success, passing the unwrapped
result value as a parameter.
public func tryMap<NewSuccess>(_ transform: (Success) throws -> NewSuccess) -> DownloadResponse<NewSuccess, Error>
Use the tryMap
method with a closure that may throw an error. For example:
let possibleData: DownloadResponse<Data> = ...
let possibleObject = possibleData.tryMap {
try JSONSerialization.jsonObject(with: $0)
}
- transform: A closure that takes the success value of the instance's result.
A success or failure DownloadResponse
depending on the result of the given closure. If this instance's result is a failure, returns the same failure.
Evaluates the specified closure when the DownloadResponse
is a failure, passing the unwrapped error as a parameter.
public func mapError<NewFailure: Error>(_ transform: (Failure) -> NewFailure) -> DownloadResponse<Success, NewFailure>
Use the mapError
function with a closure that does not throw. For example:
let possibleData: DownloadResponse<Data> = ...
let withMyError = possibleData.mapError { MyError.error($0) }
- transform: A closure that takes the error of the instance.
A DownloadResponse
instance containing the result of the transform.
Evaluates the specified closure when the DownloadResponse
is a failure, passing the unwrapped error as a parameter.
public func tryMapError<NewFailure: Error>(_ transform: (Failure) throws -> NewFailure) -> DownloadResponse<Success, Error>
Use the tryMapError
function with a closure that may throw an error. For example:
let possibleData: DownloadResponse<Data> = ...
let possibleObject = possibleData.tryMapError {
try someFailableFunction(taking: $0)
}
- transform: A throwing closure that takes the error of the instance.
A DownloadResponse
instance containing the result of the transform.
Generated at 2020-09-24T22:11:06+0000 using swift-doc 1.0.0-beta.4.
Types
- AF
- AFError
- AFError.MultipartEncodingFailureReason
- AFError.ParameterEncoderFailureReason
- AFError.ParameterEncoderFailureReason.RequiredComponent
- AFError.ParameterEncodingFailureReason
- AFError.ResponseSerializationFailureReason
- AFError.ResponseValidationFailureReason
- AFError.ServerTrustFailureReason
- AFError.ServerTrustFailureReason.Output
- AFError.URLRequestValidationFailureReason
- Adapter
- AlamofireExtension
- AlamofireNotifications
- ClosureEventMonitor
- CompositeEventMonitor
- CompositeTrustEvaluator
- ConnectionLostRetryPolicy
- DataRequest
- DataResponse
- DataResponseSerializer
- DecodableResponseSerializer
- DefaultTrustEvaluator
- DisabledEvaluator
- DownloadRequest
- DownloadRequest.Downloadable
- DownloadRequest.Options
- DownloadResponse
- Empty
- GoogleXSSIPreprocessor
- HTTPHeader
- HTTPHeaders
- HTTPMethod
- Interceptor
- JSONEncoding
- JSONParameterEncoder
- JSONResponseSerializer
- MultipartFormData
- NetworkReachabilityManager
- NetworkReachabilityManager.NetworkReachabilityStatus
- NetworkReachabilityManager.NetworkReachabilityStatus.ConnectionType
- PassthroughPreprocessor
- PinnedCertificatesTrustEvaluator
- PublicKeysTrustEvaluator
- Redirector
- Redirector.Behavior
- Request
- Request.State
- ResponseCacher
- ResponseCacher.Behavior
- Retrier
- RetryPolicy
- RetryResult
- RevocationTrustEvaluator
- RevocationTrustEvaluator.Options
- ServerTrustManager
- Session
- SessionDelegate
- StringResponseSerializer
- URLEncodedFormEncoder
- URLEncodedFormEncoder.ArrayEncoding
- URLEncodedFormEncoder.BoolEncoding
- URLEncodedFormEncoder.DataEncoding
- URLEncodedFormEncoder.DateEncoding
- URLEncodedFormEncoder.Error
- URLEncodedFormEncoder.KeyEncoding
- URLEncodedFormEncoder.SpaceEncoding
- URLEncodedFormParameterEncoder
- URLEncodedFormParameterEncoder.Destination
- URLEncoding
- URLEncoding.ArrayEncoding
- URLEncoding.BoolEncoding
- URLEncoding.Destination
- UploadRequest
- UploadRequest.Uploadable
Protocols
- AlamofireExtended
- CachedResponseHandler
- DataDecoder
- DataPreprocessor
- DataResponseSerializerProtocol
- DownloadResponseSerializerProtocol
- EmptyResponse
- EventMonitor
- ParameterEncoder
- ParameterEncoding
- RedirectHandler
- RequestAdapter
- RequestDelegate
- RequestInterceptor
- RequestRetrier
- ResponseSerializer
- ServerTrustEvaluating
- URLConvertible
- URLRequestConvertible
- UploadConvertible
- UploadableConvertible