读取本地文件:
//从文件中调取用户信息
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"user.plist"];
NSDictionary *userlist_info = [NSKeyedUnarchiver unarchiveObjectWithFile:filePath];
归档数据到本地文件:
//归档用户信息数据
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"user.plist"];
NSDictionary *userinfo = [NSKeyedUnarchiver unarchiveObjectWithFile:filePath];
NSMutableDictionary *new_userinfo = [[NSMutableDictionary alloc] init];
for(NSString *key in userinfo){
[new_userinfo setValue:(NSDictionary *)[userinfo objectForKey:key] forKey:key];
}
[new_userinfo setValue:login_info forKey:username_text];
[NSKeyedArchiver archiveRootObject:new_userinfo toFile:filePath];