Re: NSNotificationCenter
Re: NSNotificationCenter
- Subject: Re: NSNotificationCenter
- From: John Love <email@hidden>
- Date: Fri, 26 Sep 2008 13:28:09 -0400
Graham Cox, Andy Lee, et. al:
This violates the spirit and purpose of notifications. Your receiver
shouldn't also be forcing the "transmitter" to transmit, as you are
doing here. Instead, the transmitter object should always send a
"status changed" message whenever its status changes. Then the fact
that it has changed can be observed by the receiver *and also any
other object that might be interested*. What you're doing here is
absurd - if you already know the transmitter's status has changed,
then you can act on that directly - you don't need to pretend to
send a notification to yourself.
Somewhere, you should have some code that is part of the
'sentNotifyObject' class that looks like this:
- (void) postStatusChanged
{
[[NSNotificationCenter defaultCenter]
postNotificationName:kStatusChangedNotification object:self];
}
In almost all cases, whenever you call the -postNotificationName:
method of NSNotificationCenter, the object you pass is 'self'. If
it's any other, chances are you've done something weird.
So, short answer: your design is a bit whiffy. ;)
I love that word "whiffy" .. so bloody English, so Rex Harrison.
I moved all -postNotificationName:object: to the receiver and so
that's done; not only that, it makes sense. I am the observer, so it's
the receiver that is responsible for posting or sending changes to
the defaultCenter.
In addition, maybe Andy is also correct when he said:
I wonder if you're confusing notifications with KVO or bindings.
Notifications have to be explicitly posted in order for observers to
respond to them.
I said originally:
Shouldn't my call to -addObserver automatically monitor
"StatusChanged" rather than my having to -postNotificationName??
It does, but only when the receiver posts.
Having said that, let me restate it, perhaps a little more accurately:
I would like to some how "bind" the observer to the receiver so that
every time the receiver changes a parameter, it automatically "posts"
that a change has occurred, without having to explicitly post.
I believe that "KVO" stands for key-value-order .. so obviously I've
got a lot of digging to do, starting with Chapter #1, where ever that
is.
John Love
_______________________________________________
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