Next Page > Hide TOC

Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

NSNotificationQueue

Inherits from
Package
com.apple.cocoa.foundation
Companion guide

Overview

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.

Tasks

Constructors

Creating and Initializing Notification Queues

Inserting and Removing Notifications from a Queue

Constructors

NSNotificationQueue

Creates an NSNotificationQueue that uses the application’s default notification center to post notifications.

public NSNotificationQueue()

Creates an NSNotificationQueue that uses the notification center specified in notificationCenter to post notifications.

public NSNotificationQueue(NSNotificationCenter notificationCenter)

Static Methods

defaultQueue

Returns the default NSNotificationQueue object for the current thread.

public static NSNotificationQueue defaultQueue()

Discussion

This object always uses the default notification center object for the same task.

Instance Methods

dequeueMatchingNotifications

Removes all notifications from the receiver that match the attributes of notification as specified by coalesceMask.

public void dequeueMatchingNotifications(NSNotification notification, int coalesceMask)

Discussion

The mask is created by combining the constants NotificationNoCoalescing, NotificationCoalescingOnName, and NotificationCoalescingOnSender.

enqueueNotification

Puts notification in the receiver.

public void enqueueNotification(NSNotification notification, int postingStyle)

Discussion

The queue posts notification to the notification center at the time indicated by postingStyle. The notification queue posts in NSRunLoop.DefaultRunLoopMode, and it coalesces only notifications in the queue that match both the notification’s name and object.

This method invokes enqueueNotificationWithCoalesceMaskForModes.

enqueueNotificationWithCoalesceMaskForModes

Puts notification in the receiver.

public void enqueueNotificationWithCoalesceMaskForModes(NSNotification notification, int postingStyle, int coalesceMask, NSArray modes)

Discussion

The queue posts notification to the notification center at the time indicated by postingStyle, but only if the run loop is in a mode identified by one of the string objects in the modes array. The notification queue coalesces related notifications in the queue as specified by coalesceMask (set using the constants NotificationNoCoalescing, NotificationCoalescingOnName, and NotificationCoalescingOnSender). If modes is null, the notification queue posts in NSRunLoop.DefaultRunLoopMode.

Constants

These constants specify how notifications are coalesced. They’re used in the third argument of enqueueNotificationWithCoalesceMaskForModes. You can OR them together to specify more than one.

Constant

Description

NotificationNoCoalescing

Do not coalesce notifications in the queue.

NotificationCoalescingOnName

Coalesce notifications with the same name.

NotificationCoalescingOnSender

Coalesce notifications with the same object.

These constants specify when notifications are posted. They’re used in both enqueueNotification and enqueueNotificationWithCoalesceMaskForModes:

Constant

Description

PostASAP

The notification is posted at the end of the current notification callout or timer.

PostWhenIdle

The notification is posted when the run loop is idle.

PostNow

The notification is posted immediately after coalescing.



Next Page > Hide TOC


© 1997, 2006 Apple Computer, Inc. All Rights Reserved. (Last updated: 2006-07-24)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.