【问题标题】:How to use AlamofireImage ProgressHandler如何使用 AlamofireImage ProgressHandler
【发布时间】:2016-05-05 01:18:20
【问题描述】:

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

【问题讨论】:

  • 什么意思? Xcode 中的自动补全应该为您填写参数。你到底有什么问题?
  • @JonShier 我不知道如何定义参数,自动完成没有帮助。

标签: swift alamofireimage


【解决方案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-16
    • 2016-07-19
    • 2023-03-16
    • 2019-08-22
    • 1970-01-01
    • 2016-02-01
    • 1970-01-01
    • 2017-01-19
    • 2016-08-10
    相关资源
    最近更新 更多