当前位置:编程学习 > wap >>

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

//收藏数据读取 与更新

-  (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];
}


 

补充:移动开发 , IOS ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,