Important: The information in this document is obsolete and should not be used for new development.
Inherits from | |
Implements | |
Package | com.apple.cocoa.foundation |
Companion guide |
NSNotification objects encapsulate information so that it can be broadcast to other objects by an NSNotificationCenter object. An NSNotification object (referred to as a notification) contains a name, an object, and an optional dictionary. The name is a tag identifying the notification. The object is any object that the poster of the notification wants to send to observers of that notification (typically, it is the object that posted the notification). The dictionary stores other related objects, if any. NSNotification objects are immutable objects.
You can create a notification object with the constructor. However, you don’t usually create your own notifications directly. The NSNotificationCenter method postNotification
allows you to conveniently post a notification without creating it first.
You can subclass NSNotification to contain information in addition to the notification name, object, and dictionary. This extra data must be agreed upon between notifiers and observers.
Throws an IllegalArgumentException
.
public NSNotification
()
Use one of the other constructors to create an instance.
Creates a notification object that associates the name aName with the object anObject.
public NSNotification
(String aName, Object anObject)
aName may not be null
.
Creates a notification object that associates the name aName with the object anObject and the dictionary of arbitrary data userInfo.
public NSNotification
(String aName, Object anObject, NSDictionary userInfo)
The dictionary userInfo may be null
. aName may not be null
.
postNotification
(NSNotificationCenter)Returns the name of the receiver.
public String name
()
Examples of this might be “PortIsInvalid” or “PhoneRinging.” Typically, you invoke this method on the notification object passed to your notification-handler method. (You specify a notification-handler method when you register to receive the notification.)
Notification names can be any string. To avoid name collisions, however, you might want to use a prefix that’s specific to your application.
Returns the object associated with the receiver.
public Object object
()
This is often the object that posted this notification. It may be null
.
Typically, you invoke this method on the notification object passed in to your notification-handler method. (You specify a notification-handler method when you register to receive the notification.)
Returns the NSDictionary associated with the receiver or null
if there is no such object.
public NSDictionary userInfo
()
The NSDictionary stores any additional objects that objects receiving the notification might use. For example, in the Application Kit, NSControl objects post the ControlTextDidChangeNotification
whenever the field editor (an NSText object) changes text inside the NSControl. This notification provides both the NSControl object and the field editor to objects registered to receive them. The field editor is returned when you access the dictionary.
© 1997, 2006 Apple Computer, Inc. All Rights Reserved. (Last updated: 2006-07-24)