views:

575

answers:

3

Can anybody explain the importance of NSNotificationCenter?

Where to use them?

What is the difference between NSNotificationCenter vs. AppDelegate?

+4  A: 

Apple has provided an Observer Pattern in the Cocoa library called the NSNotificationCenter.

The basic idea is that a listener registers with a broadcaster using some predefined protocol. At some later point, the broadcaster is told to notify all of its listeners, where it calls some function on each of its listeners and passes certain arguments along. This allows for asynchronous message passing between two different objects that don't have to know about one-another, they just have to know about the broadcaster.

You can find more details about it here: http://numbergrinder.com/node/32

The Application Delegate is an object which receives notifications when the UIApplication object reaches certain states. In many respects, it is a specialized one-to-one Observer pattern.

You can read more about it here: http://stackoverflow.com/questions/652460/what-is-the-appdelegate-for-and-how-do-i-know-when-to-use-it

Benjamin Ortuzar
+1  A: 

If you come from an Actionscript background then NSNotification is like adding listeners to objects I guess.

Lee Probert
+3  A: 

I've written two short tutorials that may help:

Basics of Notifications

NSNotification, UserInfo and Object Methods

John

iOSDevTips.com

John
Hi john, Thanks for these tutorials.
raaz