のサブクラスを作りたいNSNotification
。カテゴリなどを作成したくありません。
ご存知かもしれませんNSNotification
が、やのようなクラス クラスタです。NSArray
NSString
クラスター クラスのサブクラスが次のことを行う必要があることは承知しています。
- 独自のストレージを宣言する
- スーパークラスのすべての初期化メソッドをオーバーライドする
- スーパークラスのプリミティブ メソッドをオーバーライドします (後述)。
これは私のサブクラスです(派手なものはありません):
@interface MYNotification : NSNotification
@end
@implementation MYNotification
- (NSString *)name { return nil; }
- (id)object { return nil; }
- (NSDictionary *)userInfo { return nil; }
- (instancetype)initWithName:(NSString *)name object:(id)object userInfo:(NSDictionary *)userInfo
{
return self = [super initWithName:name object:object userInfo:userInfo];
}
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
return self = [super initWithCoder:aDecoder];
}
@end
私がそれを使用すると、私は異常な結果を得る:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** initialization method -initWithName:object:userInfo: cannot be sent to an abstract object of class MYNotification: Create a concrete instance!'
から継承するには他に何をしなければなりませんNSNotification
か?