测试已测试 | ✗ |
语言语言 | SwiftSwift |
许可证 | MIT |
发布日期最新版本 | 2017 年 5 月 |
SwiftSwift 版本 | 3.1 |
SPM支持 SPM | ✗ |
由Jin Sasaki维护。
Swift 的优先级多图像下载器
单次下载 | 带优先级的多个下载 |
---|---|
![]() |
![]() |
import Vulcan
// Single downloading
imageView.vl.setImage(url: URL(string: "/path/to/image")!)
// Multi downloading
// This image will be overridden by the image of higher priority URL.
imageView.vl.setImage(urls: [
.url(URL(string: "/path/to/image")!, priority: 100),
.url(URL(string: "/path/to/image")!, priority: 1000)
])
如果您通过 CocoaPods 安装,请添加 pod 'Vulcan/WebP'
。如果您通过 Carthage 安装,请在项目中添加 SwiftWebP.framework
。
import Vulcan
import SwiftWebP // Only installed via Carthage
extension WebPDecoder: ImageDecoder {
public func decode(data: Data, response: HTTPURLResponse, options: ImageDecodeOptions?) throws -> Image {
let contentTypes = response.allHeaderFields.filter({ ($0.key as? String ?? "").lowercased() == "content-type" })
guard
let contentType = contentTypes.first,
let value = contentType.value as? String,
value == "image/webp",
let image = WebPDecoder.decode(data) else {
return try DefaultImageDecoder().decode(data: data, response: response, options: options)
}
return image
}
}
// Set decoder to shared ImageDownloader
Vulcan.defaultImageDownloader.decoder = WebPDecoder()
// Request image with URL
imageView.vl.setImage(url: URL(string: "/path/to/image")!)