kye kye - 10 months ago 127
Swift Question

How to use AlamofireImage ProgressHandler

Im having a hard to figuring out how exactly I can define the

parameter. The
is defined as
public typealias ProgressHandler = (bytesSent: Int64, totalBytesSent: Int64, totalExpectedBytes: Int64) -> Void
More information can be found here

let URLRequest = NSURLRequest(URL: NSURL(string: "")!)
ImageDownloader().downloadImages(URLRequests: [URLRequest], filter: nil,
progress: (init progress here), progressQueue: dispatch_get_main_queue(), completion: {
_ in

NOT A DUPLICATE! Answer/question referenced is what lead to this feature being implemented


Define it as you would any closure in Swift. You can give the captured parameters any names you want, or none using _, but you need to have 3. For instance:

ImageDownloader().downloadImage(URLRequest: "", progress: { (bytesRead, totalBytesRead, totalExpectedBytesToRead) in
    print("Read:\(bytesRead), Total Read: \(totalBytesRead), Expected: \(totalExpectedBytesToRead)")