Pros/cons of KVO vs. NSNotification
Pros/cons of KVO vs. NSNotification
- Subject: Pros/cons of KVO vs. NSNotification
- From: Michael Norris <email@hidden>
- Date: Sun, 5 Aug 2007 13:24:03 +0200
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.
Both methodologies seem to have their pros and cons. Using KVO is
quite elegant and simplifies a number of things, but on the downside
the view has to "know" about the model (or at least the model's
controller), and requires setting up an outlet in the view class and
connecting it in IB. Using NSNotifications doesn't require this
connection, which perhaps seems to me to be better MVC practice, but
the con is it can be cumbersome setting up the various notifications
in the model object.
Can anyone explain briefly their preferred method for triggering a
method in one class when some property of another class changes, or
in which situations KVO should be preferred over NSNotifications and
vice-versa? I would like to get this straight in my head before
proceeding with a new project, so that my planning will be improved.
Thanks
Michael
_______________________________________________
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