iOS开发之归档解档runtime封装演示
2016-02-23 22:15
435 查看
摘要: 只需要一个宏,就可以搞定归档解档操作
年后打算换工作,闲时整理了一下runtime,顺便把之前用到的归档解档,整理了一下,代码如下:
标黄色为调用的主要代码
调用示例:
#import <Foundation/Foundation.h>
#warning -.使用第1步:遵守协议
@interface Person : NSObject<NSCoding>
//属性
@property (nonatomic,assign) int age;
@property (nonatomic,copy) NSString *name;
@property (nonatomic,assign) double height;
@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
年后打算换工作,闲时整理了一下runtime,顺便把之前用到的归档解档,整理了一下,代码如下:
标黄色为调用的主要代码
调用示例:
#import <Foundation/Foundation.h>
#warning -.使用第1步:遵守协议
@interface Person : NSObject<NSCoding>
//属性
@property (nonatomic,assign) int age;
@property (nonatomic,copy) NSString *name;
@property (nonatomic,assign) double height;
@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
相关文章推荐
- Java Runtime Environment 5.0 Update 12 下载
- 自己简单封装的一个CDialog类实例
- PHP类的封装与继承详解
- 理解javascript封装
- javascript封装简单实现方法
- 封装好的一个万能检测表单的方法
- jquery datatable后台封装数据示例代码
- 详解js中class的多种函数封装方法
- c#基础学习之封装
- 使用对象封装ajax重复调用的方法
- Java游戏服务器之数据库表存取封装
- 纯JavaScript实现的兼容各浏览器的添加和移除事件封装
- php set_magic_quotes_runtime() 函数过时解决方法
- PHP面向对象三大特点学习(充分理解抽象、封装、继承、多态)
- Asp.Net 程序错误Runtime Error原因与解决
- javascript的函数、创建对象、封装、属性和方法、继承
- System 类 和 Runtime 类的常用用法介绍
- 异步的SQL数据库封装详解
- 深入解析C++编程中类的封装特性
- C++封装IATHOOK类实例