翠鸟和雨燕3-无法使用url设置图像 [英] Kingfisher and swift 3 - cannot set image with url

查看:159
本文介绍了翠鸟和雨燕3-无法使用url设置图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

检查文档和迁移指南,我应该能够使用以下代码设置新图像:

Checking the documentation and the migration guide, I should be able to set a new image using this code:

imageView.kf.setImage(with:url ...) 

但是实际上我无法在库中找到此方法,我只会看到:

but actually I cannot find this method in the library, I only see:

imageView.kf.setImage(with:Resource... )

尽管我在文档中找不到任何内容,但是我不确切知道该资源应如何工作.

I don't know exactly how this resource shoud work though since I cannot find anything in the documentation.

推荐答案

Resource是协议. URL已扩展为符合此协议.因此,您可以这样做:

Resource is a protocol. URL has been extended to conform to this protocol. So you can do:

let url = URL(string: ...)!
imageView.kf.setImage(with: url)


如果您想对Kingfisher缓存中的密钥使用什么进行控制,可以使用ImageResource:

let identifier = "..."
let url = URL(string: "http://example.com/images/identifier=\(identifier)")!
let resource = ImageResource(downloadURL: url, cacheKey: identifier)

imageView.kf.setImage(with: resource)

这篇关于翠鸟和雨燕3-无法使用url设置图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆