NSNotificationCenter problem

Christiaan Hofman cmhofman at gmail.com
Thu Nov 1 03:44:55 PDT 2007


On 1 Nov 2007, at 11:15 AM, Andreas Höschler wrote:

> Hi all,
>
> I have a very weird problem that causes me tearing my hair out. For  
> the first time in my life something works beautifully well under  
> GNUstep but not at all under MacOSX. And I have no idea why. I do
>
>    [[NSNotificationCenter defaultCenter] addObserver:self  
> selector:@selector(storeDidRevert:)  
> name:SOInvalidatedAllObjectsInStoreNotification  
> object:editingContext];
>
>    [[NSNotificationCenter defaultCenter]  
> postNotificationName:SOInvalidatedAllObjectsInStoreNotification  
> object:editingContext];
>
> - (void)storeDidRevert:(NSNotification *)notification
> {
>    NSLog(@"storeDidRevert...");
> }
>
> This works initially, but when I trigger
>
>    [[NSNotificationCenter defaultCenter]  
> postNotificationName:SOInvalidatedAllObjectsInStoreNotification  
> object:editingContext];
>
> again, storeDidRevert: is not called anymore (only under MacOSX).  
> My first guess was there must be an removeObserver: statement  
> anywhere, but there is none. And I use exactly the same code on  
> GNUstep where my code works perfectly! :-(
>

Are you also using the same (identical) editingContext object?

> Any idea how this can be tracked done efficiently (with gdb)? Under  
> GNUstep I would raise an exception in removeObserver if  
> notificationName is SOInvalidatedAllObjectsInStoreNotification but  
> on MacOSX I cannot simply alter and recompile the code of  
> NSNotificationCenter.
>
> Hints are greatly appreciated!
>
> Thanks,
>
>   Andreas

You can always use a subclass and poseAsClass: for debugging. make  
sure you do it early enough (e.g. at the start of main()).

Christiaan




More information about the MacOSX-dev mailing list