docs/docsets/Alamofire.docset/Contents/Resources/Documents/Structs/DownloadResponse.html
public struct DownloadResponse<Success, Failure> : Sendable where Success : Sendable, Failure : Error
extension DownloadResponse: CustomStringConvertible, CustomDebugStringConvertible
Used to store all data associated with a serialized response of a download request.
`
request
`
The URL request sent to the server.
Swift
public let request: URLRequest?
`
response
`
The server’s response to the URL request.
Swift
public let response: HTTPURLResponse?
`
fileURL
`
The final destination URL of the data returned from the server after it is moved.
Swift
public let fileURL: URL?
`
resumeData
`
The resume data generated if the request was cancelled.
Swift
public let resumeData: Data?
`
metrics
`
The final metrics of the response.
Note
Due to FB7624529, collection of URLSessionTaskMetrics on watchOS is currently disabled.`
Swift
public let metrics: URLSessionTaskMetrics?
`
serializationDuration
`
The time taken to serialize the response.
Swift
public let serializationDuration: TimeInterval
`
result
`
The result of response serialization.
Swift
public let result: Result<Success, Failure>
`
value
`
Returns the associated value of the result if it is a success, nil otherwise.
Swift
public var value: Success? { get }
`
error
`
Returns the associated error value if the result if it is a failure, nil otherwise.
Swift
public var error: Failure? { get }
`
init(request:response:fileURL:resumeData:metrics:serializationDuration:result:)
`
Creates a DownloadResponse instance with the specified parameters derived from response serialization.
Swift
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.
|
| fileURL |
The final destination URL of the data returned from the server after it is moved.
|
| resumeData |
The resume Data generated if the request was cancelled.
|
| metrics |
The URLSessionTaskMetrics of the DownloadRequest.
|
| serializationDuration |
The duration taken by serialization.
|
| result |
The Result of response serialization.
|
`
description
`
The textual representation used when written to an output stream, which includes whether the result was a success or failure.
Swift
public var description: String { get }
`
debugDescription
`
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.
Swift
public var debugDescription: String { get }
`
map(_:)
`
Evaluates the given closure when the result of this DownloadResponse is a success, passing the unwrapped result value as a parameter.
Use the map method with a closure that does not throw. For example:
let possibleData: DownloadResponse<Data> = ...
let possibleInt = possibleData.map { $0.count }
Swift
public func map<NewSuccess>(_ transform: (Success) -> NewSuccess) -> DownloadResponse<NewSuccess, Failure> where NewSuccess : Sendable
| 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.
`
tryMap(_:)
`
Evaluates the given closure when the result of this DownloadResponse is a success, passing the unwrapped result value as a parameter.
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)
}
Swift
public func tryMap<NewSuccess>(_ transform: (Success) throws -> NewSuccess) -> DownloadResponse<NewSuccess, any Error> where NewSuccess : Sendable
| 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.
`
mapError(_:)
`
Evaluates the specified closure when the DownloadResponse is a failure, passing the unwrapped error as a parameter.
Use the mapError function with a closure that does not throw. For example:
let possibleData: DownloadResponse<Data> = ...
let withMyError = possibleData.mapError { MyError.error($0) }
Swift
public func mapError<NewFailure>(_ transform: (Failure) -> NewFailure) -> DownloadResponse<Success, NewFailure> where NewFailure : Error
| transform |
A closure that takes the error of the instance.
|
A DownloadResponse instance containing the result of the transform.
`
tryMapError(_:)
`
Evaluates the specified closure when the DownloadResponse 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: DownloadResponse<Data> = ...
let possibleObject = possibleData.tryMapError {
try someFailableFunction(taking: $0)
}
Swift
public func tryMapError<NewFailure>(_ transform: (Failure) throws -> NewFailure) -> DownloadResponse<Success, any Error> where NewFailure : Error
| transform |
A throwing closure that takes the error of the instance.
|
A DownloadResponse instance containing the result of the transform.