DataRequest
class DataRequest : Alamofire.Request
-
Adds the content types specified to the list of acceptable images content types for validation.
Declaration
Swift
public class func addAcceptableImageContentTypes(_ contentTypes: Set<String>)
Parameters
contentTypes
The additional content types.
-
Creates a response serializer that returns an image initialized from the response data using the specified image options.
Declaration
Swift
public class func imageResponseSerializer( imageScale: CGFloat = DataRequest.imageScale, inflateResponseImage: Bool = true) -> DataResponseSerializer<Image>
Parameters
imageScale
The scale factor used when interpreting the image data to construct
responseImage
. Specifying a scale factor of 1.0 results in an image whose size matches the pixel-based dimensions of the image. Applying a different scale factor changes the size of the image as reported by the size property.Screen.scale
by default.inflateResponseImage
Whether to automatically inflate response image data for compressed formats (such as PNG or JPEG). Enabling this can significantly improve drawing performance as it allows a bitmap representation to be constructed in the background rather than on the main thread.
true
by default.Return Value
An image response serializer.
-
Adds a response handler to be called once the request has finished.
Declaration
Swift
public func responseImage( imageScale: CGFloat = DataRequest.imageScale, inflateResponseImage: Bool = true, queue: DispatchQueue? = nil, completionHandler: @escaping (DataResponse<Image>) -> Void) -> Self
Parameters
imageScale
The scale factor used when interpreting the image data to construct
responseImage
. Specifying a scale factor of 1.0 results in an image whose size matches the pixel-based dimensions of the image. Applying a different scale factor changes the size of the image as reported by the size property. This is set to the value of scale of the main screen by default, which automatically scales images for retina displays, for instance.Screen.scale
by default.inflateResponseImage
Whether to automatically inflate response image data for compressed formats (such as PNG or JPEG). Enabling this can significantly improve drawing performance as it allows a bitmap representation to be constructed in the background rather than on the main thread.
true
by default.queue
The queue on which the completion handler is dispatched.
nil
by default, which results in usingDispatchQueue.main
.completionHandler
A closure to be executed once the request has finished. The closure takes 4 arguments: the URL request, the URL response, if one was received, the image, if one could be created from the URL response and data, and any error produced while creating the image.
Return Value
The request.
-
Sets a closure to be called periodically during the lifecycle of the request as data is read from the server and converted into images.
Declaration
Swift
public func streamImage( imageScale: CGFloat = DataRequest.imageScale, inflateResponseImage: Bool = true, completionHandler: @escaping (Image) -> Void) -> Self
Parameters
imageScale
The scale factor used when interpreting the image data to construct
responseImage
. Specifying a scale factor of 1.0 results in an image whose size matches the pixel-based dimensions of the image. Applying a different scale factor changes the size of the image as reported by the size property. This is set to the value of scale of the main screen by default, which automatically scales images for retina displays, for instance.Screen.scale
by default.inflateResponseImage
Whether to automatically inflate response image data for compressed formats (such as PNG or JPEG). Enabling this can significantly improve drawing performance as it allows a bitmap representation to be constructed in the background rather than on the main thread.
true
by default.completionHandler
A closure to be executed when the request has new image. The closure takes 1 argument: the image, if one could be created from the data.
Return Value
The request.
-
Undocumented
Declaration
Swift
public class var imageScale: CGFloat
-
Creates a response serializer that returns an image initialized from the response data.
-
Adds a response handler to be called once the request has finished.
-
Sets a closure to be called periodically during the lifecycle of the request as data is read from the server and converted into images.
-
Returns whether the content type of the response matches one of the acceptable content types.
Throws
An
AFError
response validation failure when an error is encountered.Declaration
Swift
public class func validateContentType(for request: URLRequest?, response: HTTPURLResponse?) throws
Parameters
request
The request.
response
The server response.