NSCoding Protocol Reference
来源:互联网 发布:多系统基础数据同步 编辑:程序博客网 时间:2024/06/09 19:27
NSCoding Protocol Reference
encodeWithCoder:
Encodes the receiver using a given archiver. (required)
Parameters
- encoder
An archiver object.
Availability
- Available in iOS 2.0 and later.
Declared In
NSObject.h
initWithCoder:
Returns an object initialized from data in a given unarchiver.(required)
Parameters
- decoder
An unarchiver object.
Return Value
self
, initialized using the datain
Availability
- Available in iOS 2.0 and later.
Declared In
NSObject.h
NSCoding协议中只有两个方法,都是require的方法,一个是把本身的类进行转码,一个是逆转换成类对象,返回一个对象,我们实战一下这个协议的用法,看看是否好用,首先写一个自定义Student类:
@interfaceStudent : NSObject<NSCoding>
@property (nonatomic, retain) NSString *name;
@property (nonatomic, retain) NSString *ID;
-(Student *)initWithName :(NSString*)newName
@end
Student类需要实现协议NSCoding,.m文件中是这样的:
@implementationStudent
@synthesize name = _name,ID = _ID;
//初始化学生类
-(Student *)initWithName:(NSString *)newName and:(NSString *)newID{
}
//学生类内部的两个属性变量分别转码
-(void)encodeWithCoder:(NSCoder *)aCoder{
}
//分别把两个属性变量根据关键字进行逆转码,最后返回一个Student类的对象
-(id)initWithCoder:(NSCoder *)aDecoder{
}
@end
自定义类Student实现了NSCoding协议以后,就可以进行归档转换了,具体实现:
- NSCoding Protocol Reference
- iOS: NSCoding Protocol的方法encodeWithCoder:
- iOS: NSCoding Protocol的方法initWithCoder:
- UIAppearance Protocol Reference
- UIScrollViewDelegate Protocol Reference
- NSCoding
- NSCoding
- NSCoding
- NSCoding
- NSCoding
- apple "Mobile Device Management Protocol Reference"
- The Apache Tomcat Connectors - AJP Protocol Reference
- Protocol Buffers Developer Guide-API Reference --C++ Generated Code
- NSCoding协议
- NSCoding解释
- NSCoding协议
- NSCoding / NSKeyedArchiver
- NSCoding协议
- sahara的架构
- 共用体
- 我的C++第四周作业1(第三章部分例题与练习题)
- linux网络编程十一:将程序后台化,以守护进程的方式运行
- Android通过URL获取网络数据
- NSCoding Protocol Reference
- 线程局部存储实现
- 奇葩实现SlidingMenu,不得不转
- Oracle 自定义TYPE 的几种用法
- STM8S TIM1时钟分频
- C++实现计数排序
- 面试题:Minimum Depth of Binary Tree
- 线程的创建和启动---实现Runnable接口创建线程类
- 怎么在eclipse里,让ctrl+鼠标点击,跳到android class里去。