Re: NSNotificationCenter : multiple messages sent to the same observer?
Re: NSNotificationCenter : multiple messages sent to the same observer?
- Subject: Re: NSNotificationCenter : multiple messages sent to the same observer?
- From: Bill Bumgarner <email@hidden>
- Date: Sun, 22 Feb 2009 10:06:10 -0800
On Feb 22, 2009, at 9:59 AM, Iceberg-Dev wrote:
Thanks for the pointer. It would be nice to have this explanation
available in the description of the
addObserver:selector:name:object: as it might be where one could
expect to find it. I filed an enhancement suggestion.
But then it would have to be repeated on -postNotification: and -
removeObserver:, etc...
The documentation, in general, tries to avoid repeating stuff.
Always click through to the programming topic as it gives the overall
design philosophy and usage patterns for the given class.
The current behavior makes it possible to implement architectures
where a client could take "more action" for any given notification
by registering more than once. Not supporting this pattern would
make such a pattern significantly more inconvenient to implement.
As well, any kind of a coalescing in the notification center is
going to increase the complexity/overhead of the observer and, in
particularly, might likely impact notification delivery speed (or,
alternatively, require the notification center to use a bunch more
memory to differentiate between "set of registered observers" and
"list of observers that I actually deliver stuff to").
I think it would just require to make the search once on
registration, not every time a notification is sent.
Assuming that your statement is made in light of trying to avoid the
bloat I alluded to in the previous paragraph, this would lead to some
very surprising behavior.
Imagine this sequence of calls...
- (void)addObserver:self selector:(SEL)aSelector
name:BobsYourUncleNotification object:(id)anObject;
- (void)addObserver:self selector:(SEL)aSelector
name:BobsYourUncleNotification object:(id)anObject;
- (void)removeObserver:self name:BobsYourUncleNotification object:
(id)anObject;
If the notification center coalesced observers on registration, the
above would mean that the notification would no longer be sent.
b.bum
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden