开发者

What is NSNotification?

开发者_如何学运维Can anybody explain the importance of NSNotificationCenter?

Where to use them?

What is the difference between NSNotificationCenter vs. AppDelegate?


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: What is the AppDelegate for and how do I know when to use it?


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


NSNotification is like notifying the other class about the changes that will happen if some action takes place in another class.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜