これは、インスタンス化されるクラスと、実際のオブジェクトを形成する方法によって異なります。また、サブクラスが処理のためにスーパーを呼び出すかどうかにも依存します。それ以外の場合、NSNotificationCenterのドキュメントにあるように、通知を受け取るオブジェクトの順序はランダムであり、サブクラスまたはスーパークラスであるかどうかには依存しません。理解を深めるために、次のサンプルを検討してください(説明が完全に明確ではないため、いくつかの例が必要です)。
例1:2つの異なるオブジェクト
ParentClass *obj1 = [[ParentClass alloc] init];
ChildClass *obj2 = [[ChildClass alloc] init];
// register both of them as listeners for NSNotificationCenter
// ...
// and now their order of receiving the notifications is non-deterministic, as they're two different instances
例2:サブクラスがスーパーを呼び出す
@implementation ParentClass
- (void) handleNotification:(NSNotification *)not
{
// handle notification
}
@end
@ipmlementation ChildClass
- (void) handleNotification:(NSNotification *)not
{
// call super
[super handleNotification:not];
// actually handle notification
// now the parent class' method will be called FIRST, as there's one actual instace, and ChildClass first passes the method onto ParentClass
}
@end