简单对象读写(I/O)操作的封装

简单对象读写操作

图下是简单对象的写入和读写,

简单对象读写(I/O)操作的封装_第1张图片
DA6AA14C-5C08-4771-8CA2-C208982125CA.png

下面是我封装的方法,想调用那个的时候直接调用,方便快捷

#import "SendBoxPaths.h"
@implementation SendBoxPaths
//获取沙盒的主路径
+ (NSString*)homePath{
    return NSHomeDirectory();
}
//获取documents路径
+ (NSString*)documentsPath{
    NSArray* documentsArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    return documentsArray.firstObject;
}
//获取Library路径
+ (NSString*)libraeyPath{
    NSArray* libraryArray = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
    return libraryArray.firstObject;
}
//获取Library/caches路径
+ (NSString*)cachesPath{
    NSArray* cachesArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    return cachesArray.firstObject;
}
//获取Library/preferences路径
+ (NSString*)preferencesPath{
//    NSArray* libraryArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString* preferences = [[self libraeyPath] stringByAppendingString:@"/preferences"];
    return preferences;
}
//获取tmp路径
+ (NSString*)tmpPath{
    return NSTemporaryDirectory();
}
@end

你可能感兴趣的:(简单对象读写(I/O)操作的封装)