沙盒用于程序的缓存。可代替内存缓存
使用中一共有3步
范例中:源图片存储于一个plist文件中
//1、在适当的时候将图片写入沙盒
[NSData writeToFile:[self cachePathWithUrl:app.icon] atomically:YES];
//2、拼接一个文件在沙盒中的全路径
-(NSString *)cachePathWithUrl:(NSString *)urlStr
{
NSstring *cachePath = [NSSearchPathForDirectoriesInDomains
(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
return [cachePath stringByAppendingPathComponent:
urlStr.lastPathCompnent];
}
//3、从沙盒加载图片
UIImage *image = [UIImage imageWithContentsOfFile:
[self cachePathWithUrl:app.icon]];