What is NSNotification?
Asked Answered
S

3

13

Can anybody explain the importance of NSNotificationCenter?

Where to use them?

What is the difference between NSNotificationCenter vs. AppDelegate?

Sterigma answered 14/12, 2009 at 11:25 Comment(0)
T
30

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?

Thiouracil answered 14/12, 2009 at 11:32 Comment(0)
S
2

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

Stevenson answered 3/2, 2010 at 19:34 Comment(0)
S
1

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

Syneresis answered 10/10, 2012 at 7:59 Comment(1)
Welcome to Stack Overflow! You answered a rather old question, which already has a detailed, accepted answer. When you answer a question, please have a look at the other answers and see if your new answer adds new insights. If not, I suggest you find some other questions to answer. Good luck!Assignor

© 2022 - 2024 — McMap. All rights reserved.