iOS瘋狂講解之複雜物件的歸檔與反歸檔

2021-07-05 08:28:10 字數 1126 閱讀 6079

列表內容需求:對複雜物件進行歸檔 反歸檔

複雜物件:工程中 自定義的資料模型類 例如乙個person類

[objc] view plaincopy

person.h
[objc] view plaincopy

//  

// person.h

// mysandbox

//

// created by long on 15/9/15.

//

#import @inte***ce person : nsobject@property (nonatomic,retain) nsstring *name;

@property (nonatomic,assign) nsinteger age;

@property (nonatomic,retain) nsdata *data;

@end

[objc] view plaincopy

//  

// person.m

// mysandbox

//

// created by long on 15/9/15.

//

#import "person.h"

@implementation person

- (void)dealloc

// 歸檔 進行編碼

- (void)encodewithcoder:(nscoder *)acoder

// 反歸檔 解碼

- (id)initwithcoder:(nscoder *)adecoder

return self;

} @end

[objc] view plaincopy

//  歸檔複雜物件  

- (void)archive

// 反歸檔

- (void)unarchive

綜述: 歸檔複雜物件時 需要遵守nscoding協議 並實現起方法 對要歸檔的物件 進行編碼

iOS瘋狂詳解之複雜物件歸檔反歸檔

需求 對複雜物件進行歸檔 反歸檔 複雜物件 工程中 自定義的資料模型類 例如乙個person類 person.h person.h mysandbox created by long on 15 9 15.import inte ce person nsobject property nonatom...

複雜物件的歸檔和反歸檔

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

iOS 物件的歸檔 解檔 runtime

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