Question

Why did Apple choose to use delegation for some communication amongst SDK objects and to post notifications to Notification Center for others?

In particular, I'm thinking about the set of keyboard appearance notifications that come from UIWindow.

Is it because the Notification Center system means that more than one object can use the keyboard appearance action as a trigger to change its state, whereas only one object would have been able to act with a delegate implementation?

Was it helpful?

Solution

Delegation allows you to execute methods (and optionally pass parameters) "backward." For example, if you have one class that references another class (parent and child), the child can fire back to the parent without referencing the parent.

Notification Center, on the other hand, listens and waits until it hears the message it is waiting for. This allows for multiple listeners in multiple view controllers to wait and listen for a given message.

As for relations, delegation is a 1 to 1 relationship while Notification Center is a 1 to 1/many relationship.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top