Ios 我如何访问<;应用之家>/从捆绑中的库/缓存?
我的应用程序从服务器下载图像。我想将这些图像保存到缓存文件夹中,然后使用Ios 我如何访问<;应用之家>/从捆绑中的库/缓存?,ios,caching,uiimage,nsbundle,Ios,Caching,Uiimage,Nsbundle,我的应用程序从服务器下载图像。我想将这些图像保存到缓存文件夹中,然后使用UIImage(名称:…进行内存缓存)访问它们。将UIImage(名称:“fileURL”,位于:NSBundle.mainBundle,compatibleWith:nil)查找缓存文件夹,还是需要创建其他捆绑包?您不想将捆绑包用于缓存文件夹。您应该使用NSFileManager获取缓存文件夹的路径。例如,在Swift 2中: let fileURL = try! NSFileManager.defaultManager(
UIImage(名称:…
进行内存缓存)访问它们。将UIImage(名称:“fileURL”,位于:NSBundle.mainBundle,compatibleWith:nil)
查找缓存文件夹,还是需要创建其他捆绑包?您不想将捆绑包用于缓存文件夹。您应该使用NSFileManager
获取缓存文件夹的路径。例如,在Swift 2中:
let fileURL = try! NSFileManager.defaultManager()
.URLForDirectory(.CachesDirectory, inDomain: .UserDomainMask, appropriateForURL: nil, create: false)
.URLByAppendingPathComponent("test.jpg")
let image = UIImage(contentsOfFile: fileURL.path!)
或Swift 3:
let fileURL = try! FileManager.default
.url(for: .cachesDirectory, in: .userDomainMask, appropriateFor: nil, create: false)
.appendingPathComponent("test.jpg")
let image = UIImage(contentsOfFile: fileURL.path)