Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSNotificationCenter: Do objects receive notifications on the same thread they are posted?

I am interested in knowing whether I can expect the observing object's method to be pushed onto the stack before the posting object's method has been completed and removed.

like image 691
Corey Floyd Avatar asked Jun 17 '09 00:06

Corey Floyd


2 Answers

The short answer is yes... "Regular notification centers deliver notifications on the thread in which the notification was posted. Distributed notification centers deliver notifications on the main thread".

However, Apple has docs on this very subject that you may find helpful, and from which the above quote was pulled:

Notification Programming Topics: Delivering Notifications to Particular Threads

like image 88
Jarret Hardie Avatar answered Sep 28 '22 10:09

Jarret Hardie


Just bothered to look it up myself, shameful:

From the class reference: NSNotificationCenter posts all notifications synchronously

Also, if you prefer, you can use NSNotificationQueue to post notifications asynchronously

like image 29
Corey Floyd Avatar answered Sep 28 '22 10:09

Corey Floyd