iOS开发之归档解档runtime封装演示

年后打算换工做,闲时整理了一下runtime,顺便把以前用到的归档解档,整理了一下,代码以下:git

标黄色为调用的主要代码atom

调用示例:spa

#import <Foundation/Foundation.h>.net

#warning -.使用第1:遵照协议get

@interface Person : NSObject<NSCoding>it

//属性io

@property (nonatomic,assign) int  age;import

@property (nonatomic,copy) NSString *name;float

@property (nonatomic,assign) double  height;im

@property (nonatomic,assign) float  weight;

 

@end

 

#import "Person.h"

#import "NSObject+Coder.h"

#import "Coding.h"

@implementation Person

#warning -使用第2: 添加忽略属性

- (NSArray *)ignoredNames{

    return @[@"_height",@"_weight"];//添加不归档解档的属性

//    return nil;//若是要归档解档所有属性,注释上一行,打开此代码

}

 

#warning -使用第3: 用宏

CodingImplementation

 

@end

 

分类及演示源代码连接: https://git.oschina.net/biyu6/HZCCoding

相关文章
相关标签/搜索