• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSNotificationCenter
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: NSNotificationCenter
      • From: Graham Cox <email@hidden>
References: 
 >NSNotificationCenter (From: John Love <email@hidden>)
 >Re: NSNotificationCenter (From: Graham Cox <email@hidden>)

  • Prev by Date: Re: problems in runModal in NSOpenPanel used with defaults
  • Next by Date: Re: sending email with attachement from cocoa
  • Previous by thread: Re: NSNotificationCenter
  • Next by thread: Re: NSNotificationCenter
  • Index(es):
    • Date
    • Thread