access object passed in NSNotification?

Slee picture Slee · Jul 19, 2011 · Viewed 20.9k times · Source

I have a NSNotification that is posting a NSDictionary:

 NSDictionary* dict = [NSDictionary dictionaryWithObjectsAndKeys:
                                          anItemID, @"ItemID",
                                          [NSString stringWithFormat:@"%i",q], @"Quantity",
                                          [NSString stringWithFormat:@"%@",[NSDate date]], @"BackOrderDate",
                                          [NSString stringWithFormat:@"%@", [NSDate date]],@"ModifiedOn",
                                          nil];

                    [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:@"InventoryUpdate" object:dict]];

How do I subscribe to this and get information from this NSDictionary?

in my viewDidLoad I have:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(recieveInventoryUpdate:) name:@"InventoryUpdate" object:nil];

and a method in the class:

- (void)recieveInventoryUpdate:(NSNotification *)notification {
    NSLog(@"%@ updated", [notification userInfo]);
}

which logs a null value of course.

Answer

alex-i picture alex-i · Jul 19, 2011

it's [notification object]

you can also send userinfo by using notificationWithName:object:userInfo: method