I think the comments above sum up some of the thinking, but I just wanted to add a couple of thoughts:
When any of those view controllers sets the current item ([myClass
setCurrentItem:(MyItem*)item] I want to notify all of the view
controllers so that they can update their UI etc...
This implies you're updating all your UIViewControllers even if they are not visible. You don't state which platform you're developing for, but in general I'd aim to only have controllers update when they absolutely need to (ie. when they are visible to the user). In which case you have the option of putting logic in viewWillAppear:
and/or viewDidAppear:
to check your model (ie. the NSMutableArray
) and update the views appropriately.
Now, the question of whether to use NSNotifications or protocol methods and delegates is a tricky one. I guess there are a few things to consider:
- Do you have a single object that owns or manages your class? Generally, this would be appropriate for a delegate - think
UITableView
, for example.
- Do you want to ensure a single object must implement methods on events - again, a protocol can ensure methods are implemented and makes documentation clear.
Otherwise notifications are pretty handy. Look at the standard frameworks and take guidance from them, but realise a lot of it is just a judgement call. Look at UITextField
, for example - it uses a UITextFieldDelegate
protocol, but also creates notifications. I'm sure there's a great reason, but would probably need to spend some time thinking about it...
Edit: For completeness, as you mention:
2.) Use NSNotification center to do this communicating when iVar is set.
Key-Value Observing (KVO) allows you to register for notifications directly with object instance variables.
From the iOS 5.1 documentation:
Key-value observing is a mechanism that enables an object to be
notified directly when a property of another object changes. Key-value
observing (or KVO) can be an important factor in the cohesiveness of
an application. It is a mode of communication between objects in
applications designed in conformance with the Model-View-Controller
design pattern. For example, you can use it to synchronize the state
of model objects with objects in the view and controller layers.
Typically, controller objects observe model objects, and views observe
controller objects or model objects.
I'd add a link to the docs but don't have my bookmarks with me at the moment.