简体   繁体   中英

How quickly is an NSNotification received?

I have a controller object implemented as a singleton, which has a cache that may evict objects at any time. I want to inform any classes that make use of this controller when an object is about to be removed so they can respond appropriately. My first instinct for this kind of behaviour was to use a delegate, as it can guarantee an immediate response, however because the controller can be accessed by a number of different classes this doesn't really fit.

Notifications are the obvious choice, however I would like to know what the rules are about the delivery of NSNotification s. Are they delivered instantly, as in a message to a delegate? Or is there an indeterminate wait before a notification is received, such that no guarantee can be made as to the speed of delivery?

They are delivered immediately. One thing to note though is that they are delivered on the thread that the notification was generated from, not the thread that it was registered to be received from.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM