1

我很难弄清楚我如何准确地定义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

4

1 回答 1

1

像在 Swift 中的任何闭包一样定义它。您可以为捕获的参数提供任何您想要的名称,或者不使用_,但您需要有 3 个。例如:

ImageDownloader().downloadImage(URLRequest: "http://httpbin.org/image/png", progress: { (bytesRead, totalBytesRead, totalExpectedBytesToRead) in
    print("Read:\(bytesRead), Total Read: \(totalBytesRead), Expected: \(totalExpectedBytesToRead)")
})
于 2016-05-05T02:46:42.077 回答