swift - 如何使用 AlamofireImage ProgressHandler

标签 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

最佳答案

像在 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/

相关文章:

ios - PFUser 未解包 - swift

ios - 使用 Alamofire 将图像加载到 UITableViewCell 并圆角

swift - 使用 Alamofireimage 从服务器获取图像后,Imageview 未更新

swift - 加载图像后更新单元格

ios - 使用 Almofireimage 下载然后缓存单元格图像

iOS - 如何在标签文本更改后动态更新 UICollectionViewCell 大小

swift - 采用可变数量参数的函数

ios - 将对象用作核心数据对象字段类型

ios - UIViewController加载和释放策略

swift - 使用 alamofireimage 在 UIImageview 中显示图像