因为项目中经常需要用到数据的存储.自己写着麻烦.就简单的封装了下.大神不喜勿喷.废话不多说直接上代码
.H文件的声明
#import@interface NSString (sandBox)
//chche目录
- (instancetype)appendCache;
//Document目录
- (instancetype)appendDocument;
//Temp目录
- (instancetype)appendTemp;
.M文件实现
#import "NSString+sandBox.h"
@implementation NSString (sandBox)
- (instancetype)appendCache
{
return [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:[self lastPathComponent]];
}
//Document目录
- (instancetype)appendDocument
{
return [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:[self lastPathComponent]];
}
//Temp目录
- (instancetype)appendTemp
{
return [NSTemporaryDirectory() stringByAppendingPathComponent:[self lastPathComponent]];
}
把他们封装成NSString分类 这样调用起来就可以一句话搞定.希望能对大家有所帮助.