如何使用 AlamofireImage ProgressHandler
How to use AlamofireImage ProgressHandler
我很难弄清楚如何准确定义 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
})
不是重复的! Answer/question 引用的是导致实现此功能的原因
像 Swift 中的任何闭包一样定义它。你可以给捕获的参数任何你想要的名字,或者 none 使用 _
,但你需要有 3 个。例如:
ImageDownloader().downloadImage(URLRequest: "http://httpbin.org/image/png", progress: { (bytesRead, totalBytesRead, totalExpectedBytesToRead) in
print("Read:\(bytesRead), Total Read: \(totalBytesRead), Expected: \(totalExpectedBytesToRead)")
})
我很难弄清楚如何准确定义 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
})
不是重复的! Answer/question 引用的是导致实现此功能的原因
像 Swift 中的任何闭包一样定义它。你可以给捕获的参数任何你想要的名字,或者 none 使用 _
,但你需要有 3 个。例如:
ImageDownloader().downloadImage(URLRequest: "http://httpbin.org/image/png", progress: { (bytesRead, totalBytesRead, totalExpectedBytesToRead) in
print("Read:\(bytesRead), Total Read: \(totalBytesRead), Expected: \(totalExpectedBytesToRead)")
})