Contents

object

The object associated with the notification.

Declaration

var object: Any? { get }

Discussion

This is often the object that posted this notification. In Objective-C, it may be nil.

Typically you use this method to find out what object a notification applies to when you receive a notification.

For example, suppose you’ve registered an object to receive the message handlePortDeath: when the PortInvalid notification is posted to the notification center and that handlePortDeath: needs to access the object monitoring the port that is now invalid. handlePortDeath: can retrieve that object as shown here:

Example of accessing notification object in Objective-C:

- (void)handlePortDeath:(NSNotification *)notification
{
    ...
    [self reclaimResourcesForPort:notification.object];
    ...
}

See Also

Getting Notification Information