歸檔和反歸檔以及檔案管理

2021-07-04 15:50:14 字數 812 閱讀 3290

關於歸檔和反歸檔,菜菜說用的不那麼多,經常用的nsdata  .我們能直接進行歸檔的只有簡單資料型別(四大類),比如nsstring ,nsmutablestring,nsarray,nsmutablearray,nsdictionary,nsmutabledictionary ,nsdata,nsmutabledata .

//獲取沙盒路徑

nsstring *filepath = nshomedirectory();

nslog(@"%@", filepath);

nsstring *bundlepath = [[nsbundle mainbundle] bundlepath];

nslog(@"%@", bundlepath);

注意:nsbundle  mainbundle也是乙個單例 .
/*

沙盒資料夾下子資料夾的作用:

document:存放持久儲存的資料

*/atomically:  資料每次寫入檔案之前需要先寫入到乙個臨時檔案中,然後將臨時檔案中的內容替換原始檔的內容,這樣保證每次寫入的資料都是完整的

*************************歸檔******************************=
建立歸檔物件的時候發現需要乙個nsdata 引數,所以我們就想到需要乙個容器來接受接受

歸檔以及反歸檔

歸檔和反歸檔 複雜的物件我們並不能通過writetofile型別的方法寫入到檔案中。這裡的複雜物件指的是在foundation框架內部存在的資料類,這個負載物件至少包含有乙個例項物件 如果想要進行歸檔和反歸檔操作,則必須遵守 協議 我們在歸檔和解檔操作時,每乙個需要乙個鍵.並且歸檔時是什麼鍵,那麼解...

歸檔與反歸檔

建立一對.h m檔案nsobject h中遵守nscoding協議 定義屬性 在.m檔案中 反序列比 id initwithcoder nscoder adecoder return self 序列比 void encoderwithcoder nscoder acoder 在需要使用的地方 m 使...

複雜物件的歸檔和反歸檔

1.首先物件類遵守nscoding 實現 方法 編碼 對應於歸檔 存 的時候 void encodewithcoder nscoder acoder 解碼 反編碼 取值 id initwithcoder nscoder adecoder return self 2.歸檔 把複雜物件存入沙盒中 初始化...