您的位置:首页 > 移动开发 > IOS开发

iOS学习笔记3—NSKeyedUnarchiver进行本地数据的读取|存储

2013-01-29 14:15 711 查看
//收藏数据读取 与更新

- (void)replaceCurrentViewData :(NSMutableArray *)array

{

DWUser *loginUser = ((AppDelegate* )[UIApplication sharedApplication].delegate).appUser;

NSMutableDictionary *tempDic= [NSKeyedUnarchiver unarchiveObjectWithData:[NSData dataWithContentsOfFile:[Utils applicationDocumentsDirectory:kCollectFilePath]]];

[tempDic setObject:array forKey:loginUser.username];

NSData *data = [NSKeyedArchiver archivedDataWithRootObject:tempDic];

[data writeToFile:[Utils applicationDocumentsDirectory:kCollectFilePath] atomically:YES];

}

沙盒路径的获取

+(NSString *)applicationDocumentsDirectory :(NSString*)filename

{

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,

NSUserDirectory,

YES);

NSString *basePath = ([paths count] >0)?[paths objectAtIndex:0]:nil;

NSString *appendPath = filename;

return [basePath stringByAppendingPathComponent:appendPath];

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: