iOS 歸檔 解檔

2021-07-22 03:00:24 字數 493 閱讀 3440

1.新建類datacache:

// 歸檔

+(void)cachewithdata:(id)data withfile:(nsstring *)file

// 解檔

+ (id)archivewithfile:(nsstring *)file

2.使用:

// 儲存路徑(college_mouth.arc 在虛擬機器上, 簡單的寫可以找到路徑, 電腦會自動找到路徑. 但是, 在真機上無法獲取路徑, 必須寫完整)

nsstring *college_mouthpath = @"/documents/college_mouth.arc";

// 歸檔

[datacache cachewithdata:result withfile:_rankinglistpath[0]];

// 解檔

_tableview.array = [datacache archivewithfile:currentdatename];

iOS 歸檔解檔

開發過程中有時需要儲存一些輕量級的資料,對於ios提供的幾種資料儲存方式在這時最合適當屬物件歸檔 nscoding 但是將物件資料進行歸檔解檔時候需要實現兩個方法 encodewithcoder和initwithencoder。encodewithcoder 編碼 initwithcoder 解碼使...

ios 歸檔解檔

如果你想讓儲存乙個自定義的物件,你就要讓這個自定義的物件去遵守這個協議,而且我們要在.m檔案中重寫 void encodewithcoder nscoder acoder 方法來告訴歸檔需要儲存哪些屬性,這個nscoder型別的物件和字典很相似。我們在自定義類的.m檔案中要實現這個方法。就比如我在p...

iOS 物件的歸檔 解檔 runtime

ios 物件的歸檔 解檔 runtime 若要例項物件實現歸檔解檔,需要該類遵守nscoding協議,及以下協議方法 專案中以ycarchivebase類為例,可直接新增屬性使用 歸檔和接檔的操作以類方法實現如下 可自己建立管理類分離出去 archivefilepath 為檔案儲存路徑 void a...