views:

65

answers:

1

Hi, I'm trying to make simple use of the NSNotification center inside my iPhone application, but I seem to be doing something wrong in this case. I was under the impression that it was possible to retrieve an object associated with a particular message, or at least a reference to the object, but using the following example code I'm getting a warning,

"NSNotification center may not respond to -object"


- (void)addNewBookmark:(NSNotificationCenter *)notification {
    Bookmark *newBookMark = (Bookmark *)[notification object];
        //Do some stuff with the bookmark object
}

Indeed, when I compile and run the code, basically nothing I try to do with the contents of the object actually gets carried out - it's simply ignored.

The post code is as follows,


- (IBAction)save:(id) sender{
    //Sending the message with the related object
    [[NSNotificationCenter defaultCenter]
     postNotificationName:@"addNewBookmark"
     object:bookmark];
}

and the bookmark object itself is just a dictionary. I also tried using the "userInfo" argument and passing the bookmark object through that, but the result was the same.

How should I be doing this? What am I doing wrong?

+2  A: 

Your addNewBookmark: method should accept an NSNotification, not an NSNotificationCenter.

NSNotification should respond to -object as expected.

A notification center is the object in charge of keeping track of who is listening and sending notifications (not centers) to them.

cobbal
oh dear I feel silly. too quick with the autocomplete. ill accept this as soon as the timer allows it.
blackkettle