如果一个类注册NSNotificationCenter
了某种类型的事件,而另一个类发布了该类型的事件,那么接收器中的代码将在发布类继续之前(同步)还是之后(异步)执行?
- (void)poster {
[[NSNotificationCenter defaultCenter]
postNotificationWithName:@"myevent"
object:nil];
NSLog(@"Hello from poster");
}
- (void)receiver {
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector:(mySelector)
name:@"myevent"
object:nil];
}
- (void) mySelector:(NSNotification *) notification {
NSLog(@"Hello from receiver");
}
在上面的代码示例中,“Hello from receiver”会打印在“Hello from caller”之前还是之后?