NSKeyedArchiver的基础用法

NSString *str = @"abc";
NSString *astr = @"efg";
NSArray *Array = [NSArray arrayWithObjects:str, astr, nil];
     
//保存数据
NSString *Path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; 
NSString *filename = [Path stringByAppendingPathComponent:@"test.plist"];
[NSKeyedArchiver archiveRootObject:Array toFile:filename];
     
str = @"a";
astr = @"";
     
//加载数据
NSArray *arr = [NSKeyedUnarchiver unarchiveObjectWithFile: filename];
str = [arr objectAtIndex:0];
astr =  [arr objectAtIndex:1];
     
NSLog(@"str:%@",str);
NSLog(@"astr:%@",astr);


你可能感兴趣的:(Path)