我很难弄清楚如何准确定义 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
最佳答案
像在 Swift 中定义任何闭包一样定义它。你可以给捕获的参数任何你想要的名字,或者使用 _
没有,但你需要有 3 个。例如:
ImageDownloader().downloadImage(URLRequest: "http://httpbin.org/image/png", progress: { (bytesRead, totalBytesRead, totalExpectedBytesToRead) in
print("Read:\(bytesRead), Total Read: \(totalBytesRead), Expected: \(totalExpectedBytesToRead)")
})
关于swift - 如何使用 AlamofireImage ProgressHandler,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37040736/