Inherits from | |
Conforms to | |
Framework | /System/Library/Frameworks/Foundation.framework |
Availability | Available in Mac OS X v10.0 and later. |
Companion guide | |
Declared in | NSNotificationQueue.h |
Related sample code |
NSNotificationQueue objects (or simply notification queues) act as buffers for notification centers (instances of NSNotificationCenter). Whereas a notification center distributes notifications when posted, notifications placed into the queue can be delayed until the end of the current pass through the run loop or until the run loop is idle. Duplicate notifications can also be coalesced so that only one notification is sent although multiple notifications are posted. A notification queue maintains notifications (instances of NSNotification) generally in a first in first out (FIFO) order. When a notification rises to the front of the queue, the queue posts it to the notification center, which in turn dispatches the notification to all objects registered as observers.
Every thread has a default notification queue, which is associated with the default notification center for the task. You can create your own notification queues and have multiple queues per center and thread.
– enqueueNotification:postingStyle:
– enqueueNotification:postingStyle:coalesceMask:forModes:
– dequeueNotificationsMatching:coalesceMask:
Returns the default notification queue for the current thread.
+ (NSNotificationQueue *)defaultQueue
Returns the default notification queue for the current thread. This notification queue uses the default notification center.
NSNotificationQueue.h
Removes all notifications from the queue that match a provided notification using provided matching criteria.
- (void)dequeueNotificationsMatching:(NSNotification *)notification coalesceMask:(NSUInteger)coalesceMask
The notification used for matching notifications to remove from the notification queue.
A mask indicating what criteria to use when matching attributes of notification to attributes of notifications in the queue. The mask is created by combining any of the constants NSNotificationNoCoalescing
, NSNotificationCoalescingOnName
, and NSNotificationCoalescingOnSender
.
NSNotificationQueue.h
Adds a notification to the notification queue with a specified posting style.
- (void)enqueueNotification:(NSNotification *)notification postingStyle:(NSPostingStyle)postingStyle
The notification to add to the queue.
The posting style for the notification. The posting style indicates when the notification queue should post the notification to its notification center.
Notifications added with this method are posted using the runloop mode NSDefaultRunLoopMode
and coalescing criteria that will coalesce only notifications that match both the notification’s name and object.
This method invokes enqueueNotification:postingStyle:coalesceMask:forModes:
.
NSNotificationQueue.h
Adds a notification to the notification queue with a specified posting style, criteria for coalescing, and runloop mode.
- (void)enqueueNotification:(NSNotification *)notification postingStyle:(NSPostingStyle)postingStyle coalesceMask:(NSUInteger)coalesceMask forModes:(NSArray *)modes
The notification to add to the queue.
The posting style for the notification. The posting style indicates when the notification queue should post the notification to its notification center.
A mask indicating what criteria to use when matching attributes of notification to attributes of notifications in the queue. The mask is created by combining any of the constants NSNotificationNoCoalescing
, NSNotificationCoalescingOnName
, and NSNotificationCoalescingOnSender
.
The list of modes the notification may be posted in. The notification queue will only post the notification to its notification center if the run loops is in one of the modes provided in the array. May be nil
, in which case it defaults to NSDefaultRunLoopMode
.
NSNotificationQueue.h
Initializes and returns a notification queue for the specified notification center.
- (id)initWithNotificationCenter:(NSNotificationCenter *)notificationCenter
The notification center used by the new notification queue.
The newly initialized notification queue.
This is the designated initializer for the NSNotificationQueue class.
NSNotificationQueue.h
These constants specify how notifications are coalesced.
typedef enum { NSNotificationNoCoalescing = 0, NSNotificationCoalescingOnName = 1, NSNotificationCoalescingOnSender = 2 } NSNotificationCoalescing;
NSNotificationNoCoalescing
Do not coalesce notifications in the queue.
Available in Mac OS X v10.0 and later.
Declared in NSNotificationQueue.h
.
NSNotificationCoalescingOnName
Coalesce notifications with the same name.
Available in Mac OS X v10.0 and later.
Declared in NSNotificationQueue.h
.
NSNotificationCoalescingOnSender
Coalesce notifications with the same object.
Available in Mac OS X v10.0 and later.
Declared in NSNotificationQueue.h
.
These constants are used in the third argument of enqueueNotification:postingStyle:coalesceMask:forModes:
. You can OR them together to specify more than one.
NSNotificationQueue.h
These constants specify when notifications are posted.
typedef enum { NSPostWhenIdle = 1, NSPostASAP = 2, NSPostNow = 3 } NSPostingStyle;
NSPostASAP
The notification is posted at the end of the current notification callout or timer.
Available in Mac OS X v10.0 and later.
Declared in NSNotificationQueue.h
.
NSPostWhenIdle
The notification is posted when the run loop is idle.
Available in Mac OS X v10.0 and later.
Declared in NSNotificationQueue.h
.
NSPostNow
The notification is posted immediately after coalescing.
Available in Mac OS X v10.0 and later.
Declared in NSNotificationQueue.h
.
These constants are used in both enqueueNotification:postingStyle:
and enqueueNotification:postingStyle:coalesceMask:forModes:
.
NSNotificationQueue.h
© 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-04-02)