문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top