Objective c 当对实现NSCoding的对象进行子类化时,是否有必要调用[super encodeWithCoder]?
我知道,当您为实现NSCoding的对象的子类编写initWithCoder方法时,必须调用superObjective c 当对实现NSCoding的对象进行子类化时,是否有必要调用[super encodeWithCoder]?,objective-c,cocoa,nscoding,Objective C,Cocoa,Nscoding,我知道,当您为实现NSCoding的对象的子类编写initWithCoder方法时,必须调用superinitWithCoder(而不是super init),但是,在encodeWithCoder的实现中,我必须调用super encodeWithCoder吗?如果您从支持编码的类继承,通常建议在encodeWithCoder:方法中使用[super encodeWithCoder:,以及[super initWithCoder:]将在initWithCoder:方法中使用 文档: 参考资料:
initWithCoder
(而不是super init
),但是,在encodeWithCoder的实现中,我必须调用super encodeWithCoder
吗?如果您从支持编码的类继承,通常建议在encodeWithCoder:
方法中使用[super encodeWithCoder:
,以及[super initWithCoder:]
将在initWithCoder:
方法中使用
文档:
参考资料:
如果该类继承自符合
(NSObject不符合)则应包括[encodeWithCoder:]方法
//协议方法
-(void)编码器WithCoder:(NSCoder*)编码器
{
[超级编码器与编码器:编码器];
/*
[coder encoder object:thensstringstancevariable];
[coder ENCODER OBJECT:然后是DICTIONARYINSTANCE变量];
[coder encoder对象类型的值:@encode(BOOL)at:&thebooleansinstancevariable];
[coder EncodeValueOfObjectType:@encode(float)at:&theFloatInstanceVariable];
*/
}
// <NSCoding> protocol methods
-(void)encodeWithCoder:(NSCoder*)coder
{
[super encodeWithCoder:coder];
/*
[coder encodeObject: theNSStringInstanceVariable];
[coder encodeObject: theNSDictionaryInstanceVariable];
[coder encodeValueOfObjCType:@encode(BOOL) at:&theBooleanInstanceVariable];
[coder encodeValueOfObjCType:@encode(float) at:&theFloatInstanceVariable];
*/
}