NSCoding を実装するオブジェクトのサブクラスの initWithCoder メソッドを記述する場合、initWithCoder
( の代わりにsuper init
) super を呼び出す必要があることはわかっていますがsuper encodeWithCoder
、encodeWithCoder の実装で呼び出す必要がありますか?
2602 次
1 に答える
24
Encodingをサポートするクラスから継承する場合は、通常、メソッドで使用するのと同じように、メソッドで使用すること[super encodeWithCoder:]
をお勧めします。encodeWithCoder:
[super initWithCoder:]
initWithCoder:
ドキュメント: NSCodingプロトコルリファレンス
参照: http: //www.cocoadev.com/index.pl?NSCoder
クラスが準拠するクラスを継承する場合(NSObjectは準拠しない)、[encodeWithCoder:]メソッドを含める必要があります。
// <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];
*/
}
于 2012-04-06T08:44:33.963 に答える