Zuzana Paulis
Zuzana Paulis

Reputation: 951

Is postNotificationName guaranteed to dispatch immediately to listeners?

If i do

[[NSNotificationCenter defaultCenter] postNotificationName:@"N" object:self];
NSLog(@"here");

The observer is notified synchronously before NSLog(@"here"); is executed... if all objects are on the same thread, is this guaranteed to be executed synchronously (immediately)?

Cannot find this to be explicitly stated

Upvotes: 3

Views: 320

Answers (1)

jrturton
jrturton

Reputation: 119272

Yes it is, quite well buried though:

Using the NSNotificationCenter’s postNotification: method and its variants, you can post a notification to a notification center. However, the invocation of the method is synchronous: before the posting object can resume its thread of execution, it must wait until the notification center dispatches the notification to all observers and returns.

Source:

https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/Notifications/Articles/NotificationQueues.html

Upvotes: 1

Related Questions