access object passed in NSNotification?
it's [notification object]
you can also send userinfo by using notificationWithName:object:userInfo:
method
It's simple, see below
- (void)recieveInventoryUpdate:(NSNotification *)notification {
NSLog(@"%@ updated",notification.object); // gives your dictionary
NSLog(@"%@ updated",notification.name); // gives keyname of notification
}
if access the notification.userinfo
, it will return null
.
You are doing it wrong. You need to use:
-(id)notificationWithName:(NSString *)aName object:(id)anObject userInfo:(NSDictionary *)userInfo
and pass the dict to the last parameter. Your "object" parameter is the object sending the notification and not the dictionary.
Object is what object is posting the notification, not a way to store the object so you can get to it. The user info is where you store information you want to keep with the notification.
[[NSNotificationCenter defaultCenter] postNotificationName:@"Inventory Update" object:self userInfo:dict];
Then register for the notification. The object can be your class, or nil to just receive all notifications of this name
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(recieveInventoryUpdate:) name:@"InventoryUpdate" object:nil];
Next use it in your selector
- (void)recieveInventoryUpdate:(NSNotification *)notification {
NSLog(@"%@ updated", [notification userInfo]);
}