无法使用 KingFisher Swift 将类型“(_) -> ()”的值转换为预期的参数类型 'CompletionHandler?'
Cannot convert value of type '(_) -> ()' to expected argument type 'CompletionHandler?' using KingFisher Swift
我正在使用名为 KingFisher 的库从 Internet 下载图像。
供参考:
https://github.com/onevcat/Kingfisher
https://cocoapods.org/pods/Kingfisher
imageView.kf.setImage(with: url)
这条指令工作完美,但我想跟踪成功,所以我添加了完成处理程序,所以文档建议这个片段。
imageView.kf.setImage(with: userInfo.getImageUrl()){ result in
switch result {
case .success(let value):
print("success")
case .failure(let error):
print(error) // The error happens
}
}
作为参考,这是作弊 sheet 我正在使用:
https://github.com/onevcat/Kingfisher/wiki/Cheat-Sheet
添加此代码段时出现此编译错误:
Cannot convert value of type '(_) -> ()' to expected argument type 'CompletionHandler?' (aka 'Optional<(Optional, Optional, CacheType, Optional) -> ()>')
Swift 4.2 翠鸟 5.1
let url = URL(string: "https://example.com/high_resolution_image.png")
let imageView = UIImageView()
imageView.kf.setImage(with: url, placeholder: nil, options: nil, progressBlock: nil) { result in
print(result)
switch result {
case .success(let value):
print("success")
print(value.source.url!)
case .failure(let error):
print(error) // The error happens
}
}
我正在使用 KingFisher 5.1.0,我没有遇到这种错误。请仔细检查您的播客文件,
pod 'Kingfisher', '~> 5.1.0'
let url = URL(string: "your image url")!
self.kf.setImage(with: url) { result in
switch result {
case .success(let value):
print("Image: \(value.image). Got from: \(value.cacheType)")
case .failure(let error):
print("Error: \(error)")
}
}
https://github.com/onevcat/Kingfisher/wiki/Cheat-Sheet
如果您使用的 pod 版本低于 5.0,显然您最终会得到
Cannot convert value of type '(_) -> ()' to expected argument type 'CompletionHandler?' (aka 'Optional<(Optional, Optional, CacheType, Optional) -> ()>')
我有类似的问题。我一直在使用 Kingfisher 4.0.0 和 Swift 4.
改成下面的就成功了,
imageView.kf.setImage(with: url, placeholder: nil, options: nil, progressBlock: nil) { image, error, cacheType, imageURL in
}
我正在使用名为 KingFisher 的库从 Internet 下载图像。 供参考:
https://github.com/onevcat/Kingfisher
https://cocoapods.org/pods/Kingfisher
imageView.kf.setImage(with: url)
这条指令工作完美,但我想跟踪成功,所以我添加了完成处理程序,所以文档建议这个片段。
imageView.kf.setImage(with: userInfo.getImageUrl()){ result in
switch result {
case .success(let value):
print("success")
case .failure(let error):
print(error) // The error happens
}
}
作为参考,这是作弊 sheet 我正在使用:
https://github.com/onevcat/Kingfisher/wiki/Cheat-Sheet
添加此代码段时出现此编译错误:
Cannot convert value of type '(_) -> ()' to expected argument type 'CompletionHandler?' (aka 'Optional<(Optional, Optional, CacheType, Optional) -> ()>')
Swift 4.2 翠鸟 5.1
let url = URL(string: "https://example.com/high_resolution_image.png")
let imageView = UIImageView()
imageView.kf.setImage(with: url, placeholder: nil, options: nil, progressBlock: nil) { result in
print(result)
switch result {
case .success(let value):
print("success")
print(value.source.url!)
case .failure(let error):
print(error) // The error happens
}
}
我正在使用 KingFisher 5.1.0,我没有遇到这种错误。请仔细检查您的播客文件,
pod 'Kingfisher', '~> 5.1.0'
let url = URL(string: "your image url")!
self.kf.setImage(with: url) { result in
switch result {
case .success(let value):
print("Image: \(value.image). Got from: \(value.cacheType)")
case .failure(let error):
print("Error: \(error)")
}
}
https://github.com/onevcat/Kingfisher/wiki/Cheat-Sheet
如果您使用的 pod 版本低于 5.0,显然您最终会得到
Cannot convert value of type '(_) -> ()' to expected argument type 'CompletionHandler?' (aka 'Optional<(Optional, Optional, CacheType, Optional) -> ()>')
我有类似的问题。我一直在使用 Kingfisher 4.0.0 和 Swift 4.
改成下面的就成功了,
imageView.kf.setImage(with: url, placeholder: nil, options: nil, progressBlock: nil) { image, error, cacheType, imageURL in
}