Hi,

I'm experiencing a problem with NSNotificationCenter when trying to use the new blocks style interface.

If I register an observer to call me back the traditional way via a selector, then all is well.

If I register an observer and pass it a block of code, the code in my block is never executed (well at least I don't see any log message, don't get any breakpoints, and if I put code with side effects in the block, I don't see the side effects happen).

I have tried passing in both [NSOperationQueue mainQueue] for the queue parameter as well as nil. Although the example code below shows me registering observers using both the traditional and block styles, I have tried this with registering either or of the two styles.

I am using blocks fine in other places in my own code where I copy the block passed to me and call it back when I've completed something. FYI, I am using Clang/LLVM, garbage collection is enabled and obviously I'm targeting 10.6 to be able to use the new API.

Must be something basic I'm missing...right? :)

Thanks!

Jeremy




- (void)myNotification:(NSNotification*)notification
{
        NSLog(@"notified the traditional way, this is printed to the log");   
}

- (id)init
{
        ...

        [[NSNotificationCenter defaultCenter] addObserver:self
                                                                                
     selector:@selector(myNotification:)
                                                                                         
name:@"myNotification"
                                                                                
        object:myObject];
                
[[NSNotificationCenter defaultCenter] addObserverForName:@"myNotification"
                                                                                
                          object:myObject
                                                                                
                           queue:nil
                                                                                
                  usingBlock:^(NSNotification* notification)
         {
NSLog(@"should be notified inside of the block, but never happens and nothing printed to the log");
         }];    

        ...
}
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to