Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is NSNotification?

Can anybody explain the importance of NSNotificationCenter?

Where to use them?

What is the difference between NSNotificationCenter vs. AppDelegate?

like image 623
raaz Avatar asked Dec 14 '09 11:12

raaz


People also ask

What is NSNotification in Swift?

An object containing information broadcast to registered observers that bridges to Notification ; use NSNotification when you need reference semantics or other Foundation-specific behavior.

What is NSNotification name?

A structure that defines the name of a notification.

What is the difference between a delegate and an NSNotification?

One obvious difference is that delegation is for sending a one-to-one message (to which the receiver can return a value) whereas notification is a one-to-many message (where the receivers cannot return anything to the sender).

What is NSNotification center?

The NSNotificationCenter is a hub that is used to listen to broadcast messages and post broadcast messages in an application. The messages that are posted are synchronous.


1 Answers

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?

like image 158
Benjamin Ortuzar Avatar answered Sep 26 '22 03:09

Benjamin Ortuzar