-
A set of options to be executed prior to moving a downloaded file from the temporary
See moreURLto the destinationURL.Declaration
Swift
public struct Options : OptionSet
-
A closure executed once a
DownloadRequesthas successfully completed in order to determine where to move the temporary file written to during the download process. The closure takes two arguments: the temporary file URL and the URL response, and returns a two arguments: the file URL where the temporary file should be moved and the options defining how the file should be moved.Declaration
Swift
public typealias Destination = (_ temporaryURL: URL, _ response: HTTPURLResponse) -> (destinationURL: URL, options: Options) -
Creates a download file destination closure which uses the default file manager to move the temporary file to a file URL in the first available directory with the specified search path directory and search path domain mask.
Declaration
Swift
public class func suggestedDownloadDestination(for directory: FileManager.SearchPathDirectory = .documentDirectory, in domain: FileManager.SearchPathDomainMask = .userDomainMask, options: Options = []) -> DestinationParameters
directoryThe search path directory.
.documentDirectoryby default.domainThe search path domain mask.
.userDomainMaskby default.optionsDownloadRequest.Optionsused when moving the downloaded file to its destination. None by default.Return Value
The
Destinationclosure.
-
Type describing the source used to create the underlying
See moreURLSessionDownloadTask.Declaration
Swift
public enum Downloadable
-
If the download is resumable and eventually cancelled, this value may be used to resume the download using the
download(resumingWith data:)API.Declaration
Swift
public var resumeData: Data? { get } -
If the download is successful, the
URLwhere the file was downloaded.Declaration
Swift
public var fileURL: URL? { get }
-
Downloadablevalue used for this instance.Declaration
Swift
public let downloadable: Downloadable -
Creates a
URLSessionTaskfrom the provided resume data.Declaration
Swift
public func task(forResumeData data: Data, using session: URLSession) -> URLSessionTaskParameters
dataDataused to resume the download.sessionURLSessionused to create theURLSessionTask.Return Value
The
URLSessionTaskcreated. -
Cancels the instance. Once cancelled, a
DownloadRequestcan no longer be resumed or suspended.Note
This method will NOT produce resume data. If you wish to cancel and produce resume data, use
cancel(producingResumeData:)orcancel(byProducingResumeData:).Declaration
Swift
@discardableResult public override func cancel() -> SelfReturn Value
The instance.
-
Cancels the instance, optionally producing resume data. Once cancelled, a
DownloadRequestcan no longer be resumed or suspended.Note
If
producingResumeDataistrue, theresumeDataproperty will be populated with any resume data, if available.Declaration
Swift
@discardableResult public func cancel(producingResumeData shouldProduceResumeData: Bool) -> SelfReturn Value
The instance.
-
Cancels the instance while producing resume data. Once cancelled, a
DownloadRequestcan no longer be resumed or suspended.Note
The resume data passed to the completion handler will also be available on the instance’s
resumeDataproperty.Declaration
Swift
@discardableResult public func cancel(byProducingResumeData completionHandler: @escaping (_ data: Data?) -> Void) -> SelfParameters
completionHandlerThe completion handler that is called when the download has been successfully cancelled. It is not guaranteed to be called on a particular queue, so you may want use an appropriate queue to perform your work.
Return Value
The instance.
-
Validates the request, using the specified closure.
Note
If validation fails, subsequent calls to response handlers will have an associated error.
Declaration
Swift
@discardableResult public func validate(_ validation: @escaping Validation) -> SelfParameters
validationValidationclosure to validate the response.Return Value
The instance.
-
Adds a handler to be called once the request has finished.
Declaration
Swift
@discardableResult public func response(queue: DispatchQueue = .main, completionHandler: @escaping (AFDownloadResponse<URL?>) -> Void) -> SelfParameters
queueThe queue on which the completion handler is dispatched.
.mainby default.completionHandlerThe code to be executed once the request has finished.
Return Value
The request.
-
Adds a handler to be called once the request has finished.
Declaration
Swift
@discardableResult public func response<Serializer: DownloadResponseSerializerProtocol>(queue: DispatchQueue = .main, responseSerializer: Serializer, completionHandler: @escaping (AFDownloadResponse<Serializer.SerializedObject>) -> Void) -> SelfParameters
queueThe queue on which the completion handler is dispatched.
.mainby default.responseSerializerThe response serializer responsible for serializing the request, response, and data contained in the destination
URL.completionHandlerThe code to be executed once the request has finished.
Return Value
The request.
-
Adds a handler to be called once the request has finished.
Declaration
Swift
@discardableResult public func responseData(queue: DispatchQueue = .main, completionHandler: @escaping (AFDownloadResponse<Data>) -> Void) -> SelfParameters
queueThe queue on which the completion handler is dispatched.
.mainby default.completionHandlerThe code to be executed once the request has finished.
Return Value
The request.
-
Adds a handler to be called once the request has finished.
Declaration
Swift
@discardableResult public func responseString(queue: DispatchQueue = .main, encoding: String.Encoding? = nil, completionHandler: @escaping (AFDownloadResponse<String>) -> Void) -> SelfParameters
queueThe queue on which the completion handler is dispatched.
.mainby default.encodingThe string encoding. Defaults to
nil, in which case the encoding will be determined from the server response, falling back to the default HTTP character set,ISO-8859-1.completionHandlerA closure to be executed once the request has finished.
Return Value
The request.
-
Adds a handler to be called once the request has finished.
Declaration
Swift
@discardableResult public func responseJSON(queue: DispatchQueue = .main, options: JSONSerialization.ReadingOptions = .allowFragments, completionHandler: @escaping (AFDownloadResponse<Any>) -> Void) -> SelfParameters
queueThe queue on which the completion handler is dispatched.
.mainby default.optionsThe JSON serialization reading options.
.allowFragmentsby default.completionHandlerA closure to be executed once the request has finished.
Return Value
The request.
-
Adds a handler to be called once the request has finished.
Declaration
Swift
@discardableResult public func responseDecodable<T: Decodable>(of type: T.Type = T.self, queue: DispatchQueue = .main, decoder: DataDecoder = JSONDecoder(), completionHandler: @escaping (AFDownloadResponse<T>) -> Void) -> SelfParameters
typeDecodabletype to decode from response data.queueThe queue on which the completion handler is dispatched.
.mainby default.decoderDataDecoderto use to decode the response.JSONDecoder()by default.completionHandlerA closure to be executed once the request has finished.
Return Value
The request.
-
A closure used to validate a request that takes a URL request, a URL response, a temporary URL and a destination URL, and returns whether the request was valid.
Declaration
Swift
public typealias Validation = (_ request: URLRequest?, _ response: HTTPURLResponse, _ fileURL: URL?) -> ValidationResult -
Validates that the response has a status code in the specified sequence.
If validation fails, subsequent calls to response handlers will have an associated error.
Declaration
Swift
@discardableResult public func validate<S>(statusCode acceptableStatusCodes: S) -> Self where S : Sequence, S.Element == IntParameters
rangeThe range of acceptable status codes.
Return Value
The request.
-
Validates that the response has a content type in the specified sequence.
If validation fails, subsequent calls to response handlers will have an associated error.
Declaration
Swift
@discardableResult public func validate<S>(contentType acceptableContentTypes: @autoclosure @escaping () -> S) -> Self where S : Sequence, S.Element == StringParameters
contentTypeThe acceptable content types, which may specify wildcard types and/or subtypes.
Return Value
The request.
-
Validates that the response has a status code in the default acceptable range of 200…299, and that the content type matches any specified in the Accept HTTP header field.
If validation fails, subsequent calls to response handlers will have an associated error.
Declaration
Swift
@discardableResult public func validate() -> SelfReturn Value
The request.
View on GitHub
Install in Dash
DownloadRequest Class Reference