Adds an entry to the notification center to receive notifications that passed to the provided block.
- iOS 4.0+
- macOS 10.6+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 2.0+
The name of the notification to register for delivery to the observer block. Specify a notification name to deliver only entries with this notification name.
nil, the sender doesn’t use notification names as criteria for delivery.
The object that sends notifications to the observer block. Specify a sender to deliver only notifications from this sender.
nil, the notification center doesn’t use the sender as criteria for the delivery.
The operation queue where the
nil, the block runs synchronously on the posting thread.
The block that executes when receiving a notification.
The notification center copies the block. The notification center strongly holds the copied block until you remove the observer registration.
The block takes one argument: the notification.
An opaque object to act as the observer. Notification center strongly holds this return value until you remove the observer registration.
If a notification triggers more than one observer block, the blocks can all execute concurrently (but on their queue or on the current thread).
The following example shows how you can register to receive locale change notifications.
Unregister an observer to stop receiving notifications. To unregister an observer, use
remove with the most specific detail possible. For example, if you used a name and object to register the observer, use the name and object to remove it.
Another common practice is to create a one-time notification by removing the observer from within the observation block, as in the following example.