DPImageCache 是 Swift 写成的 UIImageView 的扩展,帮助加载图像异步存储本地文件缓存。
使用:
let dirName = "cache" func createCacheDirectory() { var fileMan = NSFileManager.defaultManager() var cacheDir = (NSSearchPathForDirectoriesInDomains( .DocumentDirectory, .UserDomainMask, true)[0] as! NSString) .stringByAppendingPathComponent(dirName) if !fileMan.fileExistsAtPath(cacheDir) { fileMan.createDirectoryAtPath( cacheDir, withIntermediateDirectories: false, attributes: nil, error: nil) } }