数据存储的常用方式

  • XML属性列表(plist)归档
NSArray *arr1 = @[@"a",@"b",@"c"];
NSString *filePath = @"xxx.data";
// 存储
[arr1 writeToFile:filePath atomically:YES];
// 读取
NSArray *arr2 = [NSArray arrayWithContentsOfFile:filePath];
  • Preference(偏好设置)
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]
// 存储
[userDefaults setObject:@"chaselen" forKey:@"username"];
[userDefaults setBool:YES forKey:@"rememberPwd"];
// 读取
NSString *username = [userDefaults objectForKey:@"username"];
BOOL rememberPwd = [userDefaults BoolForKey:@"rememberPwd"];
  • NSKeyedArchiver归档(NSCoding)

    自定义的类遵守协议(实现encodeWithCoder方法和initWithCoder方法)

  • SQLite3

  • Core Data

你可能感兴趣的:(数据存储的常用方式)