Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 当对实现NSCoding的对象进行子类化时,是否有必要调用[super encodeWithCoder]?_Objective C_Cocoa_Nscoding - Fatal编程技术网

Objective c 当对实现NSCoding的对象进行子类化时,是否有必要调用[super encodeWithCoder]?

Objective 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:方法中使用 文档: 参考资料:

我知道,当您为实现NSCoding的对象的子类编写initWithCoder方法时,必须调用super
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];
    */
}