tags:

views:

41

answers:

2

How can I fetch object from NSNotification object? Any clue?

+1  A: 

Quite simple. Use the object method of NSNotification.

- (void)myMethod:(NSNotification* notification) {
    // Example with a NSArray
    NSArray* myArray = (NSArray*)[notification object];
    // Do stuff
}
Henrik P. Hessel
A: 

When you post you can wrap many objects in an NSDictionary.

NSDictionary *userInfo=[NSDictionary withObjectsAndKeys:obj1,key1,obj2,key2,nil];
[[NSNotificationCenter defaultCenter] postNotificationName:@"NOTI_NAME" 
                                                    object:self
                                                  userInfo:userInfo];

In you observer:

-(void)notiObserver:(NSNotification *)notification{

    NSDictionary *userInfo=[notification userInfo];
    OBJ1 *obj1=[userInfo objectForKey:key1];

}
Jorge
Thank you so much sir
Abhinav