O'Reilly logo

Cocoa in a Nutshell by James Duncan Davidson, Michael Beam

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

NSNotification — Mac OS X 10.0

Synopsis

Notifications provide a mechanism for objects that have no other way to communicate with each other. The model used is a multicast model, in which client objects register themselves with a notification center to be notified in response to a certain event, which is encapsulated in an NSNotification object. NSNotification represents both notifications to the notification center, and the notifications that are sent out to the observers of a particular notification.

Clients generally interact with notifications as receivers; that is, they don’t create notifications, but extract key bits of information out of received notifications. To obtain information about a notification we use the three methods name, userInfo, and object, which return the notification name, userInfo dictionary, and the notification’s associated object, respectively.

image with no caption

@interface NSNotification : NSObject <NSCoding, NSCopying>
                                  // Convenience Constructors
   + (id)notificationWithName:(NSString *)aName 
                                 object:(id)anObject;
   + (id)notificationWithName:(NSString *)aName 
                                 object:(id)anObject 
                                 userInfo:(NSDictionary *)aUserInfo;
                                  // Instance Methods
   - (NSString *)name;
   - (id)object;
   - (NSDictionary *)userInfo;
                                  // Methods Implementing NSCoding
   - (void)encodeWithCoder:(NSCoder *)aCoder;
   - (id)initWithCoder:(NSCoder *)aDecoder;
                                  // Methods Implementing NSCopying ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required