ios - 无法将类型“(_)->()”的值转换为预期的参数类型“CompletionHandler?” 使用 KingFisher Swift
问题描述
我正在使用一个名为 KingFisher 的库从互联网下载图像。供参考:
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
}
}
作为参考,这是我正在使用的备忘单:
https://github.com/onevcat/Kingfisher/wiki/Cheat-Sheet
添加此代码段时,我收到此编译错误:
无法将类型“(_)->()”的值转换为预期的参数类型“CompletionHandler?” (aka 'Optional<(Optional, Optional, CacheType, Optional) -> ()>')
解决方案
迅捷 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
}
}
推荐阅读
- asp.net-core-3.1 - .net core Ocelot 找不到名为“ConfigureDevelopment”或“Configure”的公共方法
- z3 - 支持 SMT 求解器中的整数除法
- azure-rest-api - 在 Azure RBAC 自定义角色中找出正确的操作集
- javascript - HTML CSS 顶部拖动条幻灯片以显示更多信息
- wpf - 在 .NET Framework 应用程序中使用 .NET Core 类库
- python - 如何在 Python 中使用正则表达式将所有内容匹配到双换行符“\n\n”?
- git - 在 github 上挑选一个合并的 PR
- mysql - MySQL - 带有 CONCAT 的内部连接 - 字段列表中的列“learning_event_name”不明确
- php - 在页面中将另一个 laravel 刀片视图显示为模式
- java - 未定义的参数返回 INT