NSKeyedArchiver的基础用法

LINK Address:http://blog.csdn.net/bl1988530/article/details/6559908

  1. NSString *str = @"abc";  
  2. NSString *astr = @"efg";  
  3. NSArray *Array = [NSArray arrayWithObjects:str, astr, nil];  
  4.        
  5. //保存数据  
  6. NSString *Path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; NSString *filename = [Path stringByAppendingPathComponent:@"test.plist"];  
  7. [NSKeyedArchiver archiveRootObject:Array toFile:filename];  
  8.        
  9. str = @"a";  
  10. astr = @"";  
  11.        
  12. //加载数据  
  13. NSArray *arr = [NSKeyedUnarchiver unarchiveObjectWithFile: filename];  
  14. str   =  [arr objectAtIndex:0];  
  15. astr =  [arr objectAtIndex:1];  
  16.        
  17. NSLog(@"str:%@",str);  
  18. NSLog(@"astr:%@",astr);  

你可能感兴趣的:(hive)