gpt4 book ai didi

swift - 如何使用 AlamofireImage ProgressHandler

转载 作者:行者123 更新时间:2023-11-28 06:44:12 24 4
gpt4 key购买 nike

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com