数据持久化

属性列表

NSUserDefault
plist文件是将某些特定的类,通过XML文件的方式保存在目录中

对象归档

@interface Person : NSObject  
@property (nonatomic, strong) NSString *name;
@end
// 归档
- (void)encodeWithCoder:(NSCoder *)aCoder{
    [super encodeWithCoder:aCoder];
    [aCoder encodeObject:self.name forKey:@"name"];
}

// 解档
- (id)initWithCoder:(NSCoder *)aDecoder{
    if (self =[super initWithCoder:aDecoder]) {
        self.name = [aDecoder decodeObjectForKey:@"name"];
    }
    return self;
}

SQLlite

Core Data

结构:

“应用程序包”
Documents //iTunes同步
Library {
Caches
Preferences //iTunes同步
}
tmp

Document

存放重要数据

NSArray *documentArr = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

Library

NSArray libraryArr = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
NSString *library = libraryArr[0];

Caches

NSArray *cachesArr = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *caches = cachesArr[0];

你可能感兴趣的:(数据持久化)