1

Im having a hard to figuring out how exactly I can define the ProgressHandler parameter. The typealias is defined aspublic typealias ProgressHandler = (bytesSent: Int64, totalBytesSent: Int64, totalExpectedBytes: Int64) -> Void More information can be found here https://github.com/Alamofire/AlamofireImage/pull/91

let URLRequest = NSURLRequest(URL: NSURL(string: "https://httpbin.org/image/jpeg")!)
    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 https://stackoverflow.com/a/33503205/5222077

Community
  • 1
  • 1
kye
  • 2,166
  • 3
  • 27
  • 41
  • What do you mean? Autocompletion in Xcode should fill in the parameters for you. What exactly is your problem? – Jon Shier May 05 '16 at 02:40
  • @JonShier I don't know how to define the parameter, autocomplete doesn't help. – kye May 05 '16 at 02:42

1 Answers1

1

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: "http://httpbin.org/image/png", progress: { (bytesRead, totalBytesRead, totalExpectedBytesToRead) in
    print("Read:\(bytesRead), Total Read: \(totalBytesRead), Expected: \(totalExpectedBytesToRead)")
})
Jon Shier
  • 12,200
  • 3
  • 35
  • 37