In general, you have 3 different methods:
- Delegation
- KVO (monitoring of key values)
- Notifications
If your model only needs to report one change object (your controller), delegation is the way to go. You may need additional work to create a new interface, add a delegate property to the model, etc., but it is definitely worth the flexibility, code reuse, design, etc. Delegation is a standard template in Cocoa programming and is widely used in the Apple API.
If your model needs to inform several objects about changes, you want to use KVO or notifications. With KVO, you can subscribe to event changes for a specific property or key on a model. For example, when the “messages” property on your model changes, any attached listeners can be notified of this change and respond accordingly.
Notifications are used when you want to send application messages to multiple listeners. Examples of standard APIs are keyboard notifications (when the keyboard is displayed / rejected), and the orientation of the interface also changes.
So, in your case, delegation or KVO is probably the best choice.
source share