I’m having trouble identifying how to tell which object posted a notification.
I subscribe to a notification in object A:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receivedNotification:) name=@"ReceivedData" object:nil]
I post a notification from object B:
[[NSNotificationCenter defaultCenter] postNotificationName:@"ReceivedData" object: self userInfo: dict];
I recieve the notification in object A:
- (void) receivedNotification: (NSNotification*) notification
{
// Method is hit fine, notification object contains data.
}
How can I tell that it was object B that sent the data and not, for instance, a object C? I need a reference to the sender. I don’t want to add the sender to the notification object being passed, as I am specifiying the sender when I call the notification in object B
The
NSNotificationclass has a method called object that returns the object associated with the notification. This is often the object that posted this notification.