Swift 编写的网络图像库:Skeets

分享到:

Skeets 是网络图像库,可以通过 HTTP 来匹配,缓存和显示图片。Skeets 是使用 Swift 编写的,使用 SwiftHTTP 构建。

//create a imageView
let imageView = UIImageView(frame: CGRectMake(0, 60, 200, 200))
self.view.addSubview(imageView)
//set the cache directory. Only have to do this once since `sharedManager` is a singleton
let paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
ImageManager.sharedManager.cache.diskDirectory = "\(paths[0])/ImageCache"
ImageManager.sharedManager.cache.cleanDisk()
//fetch the image
ImageManager.sharedManager.fetch("http://vluxe.io/assets/images/logo.png",
progress: { (status: Double) in
println("updating some UI for this: \(status)") //useful if you have some kind of progress dialog as the image loads
},success: { (data: NSData) in
println("got an image!")
imageView.image = UIImage(data: data) //set the image data
}, failure: { (error: NSError) in
println("failed to get an image: \(error)")
})

特性

  • 多级缓存,内存和硬盘缓存

  • 非阻塞 IO,所有 HTTP 和硬盘 IO 都在后台运行

  • 简单的一个方法就可以加载一个远程图片

  • 健壮,快速和可定制的缓存

  • 几百行简单简洁代码库

  • 处理冗余图像请求,一个请求多个查询

Swift 编写的网络图像库:Skeets

项目主页:http://www.open-open.com/lib/view/home/1413361100106

昵    称:
验证码:

相关文档: