当前位置:编程学习 > 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 © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,