I am using MPMoviePlayerController
in a project. The loadState
of the MPMoviePlayerController
object is observed using NSNotificationCenter
.
Why did Apple choose NSNotificationCenter
in this situation instead of using delegation?
You may have more than one class that is interested in the loadState of the MPMoviePlayerController. A plausible example of this is the fact that Apple may be using the loadState-related notification to do some of their own stuff under the hood. Now you come along and also express interest in the same notification. Using NSNotificationCenter, you both can say “Hey, I want to be notified when the loadState of this player changes”.
In the case of a protocol (delegation), it’s generally a one-to-one relationship. An object, in your example the player, could only have one delegate. So if Apple needed to know about the loadState, and you needed to learn about the loadState also, one of you would be out of luck!
NSNotificationCenter has what’s considered a “loosely coupled” relationship with the object that posts a notification and the object(s) that observes that notification. In delegation, however, the relationship tends to be significantly tighter.
2