• 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: Pros/cons of KVO vs. NSNotification
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Pros/cons of KVO vs. NSNotification


  • Subject: Re: Pros/cons of KVO vs. NSNotification
  • From: Alastair Houghton <email@hidden>
  • Date: Mon, 20 Aug 2007 16:44:02 +0100

On 5 Aug 2007, at 12:24, Michael Norris wrote:

I'm sorry if this is a FAQ, but as far as I can see, there are two ways to trigger a routine in a view when some property of a model class changes: key-value observing and NSNotification.

I wonder if someone could give me a general rule-of-thumb as to when I should use KVO and when I should use notifications. In my current project, I'm using both, though I don't feel I've quite grasped when it is appropriate to do one and not the other.

Hi Michael,

I know it's been a while since you posted your question, but I've been pondering this myself today and wanted to see if anyone else had anything to say about it (so I spotted your post in Google).

My take, for what it's worth, is that you should limit your use of KVO to cases like bindings where it's actually necessary. Why? Because, as Brent Simmons pointed out on his blog earlier this year (<http://inessential.com/?comments=1&postid=3405>), there's nothing in the setter to indicate that some other object might do something as a result of sending a message. In that sense, it's a bit like the "come from" statement in Intercal... a statement somewhere else in the code can cause control flow to deviate radically from what you would normally expect, and there's no easy way to find out if such a statement exists.

Cocoa notifications, on the other hand, have to be explicitly posted, which means that you can at least see in your code that a notification is going to happen in a particular case.

As a result, I think Cocoa notifications, sent explicitly via NSNotificationCenter, are generally a better choice, where they are necessary.

Kind regards,

Alastair.

--
http://alastairs-place.net


_______________________________________________

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


References: 
 >Pros/cons of KVO vs. NSNotification (From: Michael Norris <email@hidden>)

  • Prev by Date: Re: Userdefaults, their initial values, and bindings
  • Next by Date: Re: Userdefaults, their initial values, and bindings
  • Previous by thread: Pros/cons of KVO vs. NSNotification
  • Next by thread: Drag with NSTableview
  • Index(es):
    • Date
    • Thread