Up

NSNotificationCenter class reference

Authors

Andrew Kachites McCallum (mccallum@gnu.ai.mit.edu)
Richard Frith-Macdonald (rfm@gnu.org)
Richard Frith-Macdonald (richard@brainstorm.co.uk)

Version: 1.24

Date: 2004/06/22 22:40:38

Copyright: (C) 1996,1999 Free Software Foundation, Inc.


Contents -

  1. Software documentation for the NSNotification class
  2. Software documentation for the NSNotificationCenter class
  3. Software documentation for the NSNotificationCenter(GNUstep) category

Software documentation for the NSNotification class

NSNotification : NSObject

Declared in:
Foundation/NSNotification.h
Conforms to:
NSCopying
NSCoding
Standards:

Represents a notification for posting to an NSNotificationCenter . Consists of a name, an object, and an optional dictionary. The notification center will check for observers registered to receive either notifications with the name, the object, or both and pass the notification instance on to them.

This class is actually the interface for a class cluster, so instances will be of a (private) subclass.

Method summary

notificationWithName: object: 

+ (NSNotification*) notificationWithName: (NSString*)name object: (id)object;

Create a new autoreleased notification by calling +notificationWithName:object:userInfo: with a nil user info argument.


notificationWithName: object: userInfo: 

+ (NSNotification*) notificationWithName: (NSString*)name object: (id)object userInfo: (NSDictionary*)info;

Create a new autoreleased notification.


name 

- (NSString*) name;

Returns the notification name.


object 

- (id) object;

Returns the notification object.


userInfo 

- (NSDictionary*) userInfo;

Returns the notification user information.


Software documentation for the NSNotificationCenter class

NSNotificationCenter : NSObject

Declared in:
Foundation/NSNotification.h
Conforms to:
GCFinalization
Standards:

GNUstep provides a framework for sending messages between objects within a process called notifications. Objects register with an NSNotificationCenter to be informed whenever other objects post NSNotification s to it matching certain criteria. The notification center processes notifications synchronously -- that is, control is only returned to the notification poster once every recipient of the notification has received it and processed it. Asynchronous processing is possible using an NSNotificationQueue .

Obtain an instance using the +defaultCenter method.

In a multithreaded process, notifications are always sent on the thread that they are posted from.

Use the NSDistributedNotificationCenter for interprocess communications on the same machine.


Instance Variables

Method summary

defaultCenter 

+ (NSNotificationCenter*) defaultCenter;

Returns the default notification center being used for this task (process). This is used for all notifications posted by the Base library unless otherwise noted.


addObserver: selector: name: object: 

- (void) addObserver: (id)observer selector: (SEL)selector name: (NSString*)name object: (id)object;

Registers observer to receive notifications with the name notificationName and/or containing object (one or both of these two must be non-nil; nil acts like a wildcard). When a notification of name name containing object is posted, observer receives a selector message with this notification as the argument. The notification center waits for the observer to finish processing the message, then informs the next registree matching the notification, and after all of this is done, control returns to the poster of the notification. Therefore the processing in the selector implementation should be short.

The notification center does not retain observer or object. Therefore, you should always send removeObserver: or removeObserver:name:object: to the notification center before releasing these objects.


postNotification: 

- (void) postNotification: (NSNotification*)notification;

Posts notification to all the observers that match its NAME and OBJECT.
The GNUstep implementation calls -postNotificationName:object:userInfo: to perform the actual posting.


postNotificationName: object: 

- (void) postNotificationName: (NSString*)name object: (id)object;

Creates and posts a notification using the -postNotificationName:object:userInfo: passing a nil user info argument.


postNotificationName: object: userInfo: 

- (void) postNotificationName: (NSString*)name object: (id)object userInfo: (NSDictionary*)info;

The preferred method for posting a notification.
For performance reasons, we don't wrap an exception handler round every message sent to an observer. This means that, if one observer raises an exception, later observers in the lists will not get the notification.


removeObserver: 

- (void) removeObserver: (id)observer;

Deregisters observer from all notifications. This should be called before the observer is deallocated.


removeObserver: name: object: 

- (void) removeObserver: (id)observer name: (NSString*)name object: (id)object;

Deregisters observer for notifications matching name and/or object. If either or both is nil, they act like wildcards. The observer may still remain registered for other notifications; use -removeObserver: to remove it from all. If observer is nil, the effect is to remove all registrees for the specified notifications, unless both observer and name are nil, in which case nothing is done.




Instance Variables for NSNotificationCenter Class

_table

@protected void* _table;

Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.





Software documentation for the NSNotificationCenter(GNUstep) category

NSNotificationCenter(GNUstep)

Declared in:
Foundation/NSNotification.h
Standards:

Defines some extensions for maximising posting performance - these options are NOT adjustable for the default notification center.

Method summary

setImmutableInPost: 

- (BOOL) setImmutableInPost: (BOOL)flag;

You can turn on 'immutability' if you KNOW that the posting of a notification will never result in an attempt to modify the center. In this case, the center can optimise delivery of notifications.


setLockingDisabled: 

- (BOOL) setLockingDisabled: (BOOL)flag;

You can disable locking in a multi-threaded program if you KNOW that only one thread will ever use the notification center.



Up