你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> iOS學習筆記3—NSKeyedUnarchiver進行本地數據的讀取|存儲

iOS學習筆記3—NSKeyedUnarchiver進行本地數據的讀取|存儲

編輯:IOS開發綜合

//收藏數據讀取 與更新

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


 

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved