#import "NSString+WJ.h" @implementation NSString (WJ) - (instancetype)cacheDir { //1.获取Caches目录 NSString *path = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject]; //2.生成绝对路径 return [path stringByAppendingPathComponent:[self lastPathComponent]]; } -(instancetype)docDir { NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES) lastObject]; return [path stringByAppendingPathComponent:[self lastPathComponent]]; } - (instancetype)tmpDir { NSString *path = NSTemporaryDirectory(); return [path stringByAppendingPathComponent:[self lastPathComponent]]; } @end
原文:http://my.oschina.net/codebywj/blog/524642