如何使用AlamofireImage ProgressHandler

时间:2016-05-05 01:18:20

标签: swift alamofireimage

我很难弄清楚我究竟能如何定义ProgressHandler参数。 typealias定义为public typealias ProgressHandler = (bytesSent: Int64, totalBytesSent: Int64, totalExpectedBytes: Int64) -> Void 更多信息可在此处找到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
        })

不是重复!引用的答案/问题是导致此功能实施的原因 https://stackoverflow.com/a/33503205/5222077

1 个答案:

答案 0 :(得分:1)

像在Swift中的任何闭包一样定义它。您可以使用_为捕获的参数提供所需的任何名称,但不需要使用ImageDownloader().downloadImage(URLRequest: "http://httpbin.org/image/png", progress: { (bytesRead, totalBytesRead, totalExpectedBytesToRead) in print("Read:\(bytesRead), Total Read: \(totalBytesRead), Expected: \(totalExpectedBytesToRead)") }) ,但是您需要拥有3.例如:

echo $CLUSTER