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

大城市里の小女人 提交于 2019-11-29 11:17:50

问题


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.


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/1004589/nsnotificationcenter-do-objects-receive-notifications-on-the-same-thread-they-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!