• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSDistributedNotificationCenter question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSDistributedNotificationCenter question


  • Subject: NSDistributedNotificationCenter question
  • From: Ronald Oussoren <email@hidden>
  • Date: Sun, 8 Jun 2003 17:15:32 +0200

Hi,

I'm one of the authors of PyObjC and one of our users complained that NSDistributedNotificationCenter doesn't work. Luckily for me a Objective-C version of his demo program gives exactly the same behaviour. I could not find in the documentation *why* it behaves as it does, hence this email.

The program below listens for nofications on the default distributed nofication center. It then posts a notification from the same process. The thing that confuses my is that the receiver of the program cannot access the original 'object' of the nofication, it is always 'nil'. Why is this?

Ronald

/*
Test program for NSDistributedNotification (sent to same application).

Problem is that the specified notification _object_, but nil is passed on.

compile with:
cc -o t distribnotif.m -framework Foundation
execute with:
./t
*/

#import <Foundation/Foundation.h>


@interface Observer :NSObject
{
}
-(void)trackNotification:(NSNotification*)notif;

@end


@implementation Observer

-(void)trackNotification:(NSNotification*)notif
{
NSLog(@"trackNotification: %@", notif);
NSLog(@"trackNotification name: %@", [notif name]);
NSLog(@"trackNotification object: %@", [notif object]);
NSLog(@"trackNotification userInfo: %@", [notif userInfo]);
}

@end


int main(void)
{
NSDistributedNotificationCenter* nc;
NSMutableDictionary* info;
Observer* observer;
NSRunLoop* rl;

[[NSAutoreleasePool alloc] init];

nc = [NSDistributedNotificationCenter defaultCenter];
observer = [[Observer alloc] init];

[nc addObserver:observer
selector:@selector(trackNotification:)
name:@"NOTIFNAME" object:nil];

info = [NSMutableDictionary dictionary];
[info setObject:@"foo" forKey:@"bar"];

[nc postNotificationName:@"NOTIFNAME"
object:@"SomeObject"
userInfo:info deliverImmediately:YES];

rl = [NSRunLoop currentRunLoop];
[rl runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.5]];

return 0;
}
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: NSDistributedNotificationCenter question
      • From: Julien Jalon <email@hidden>
    • Re: NSDistributedNotificationCenter question
      • From: David Remahl <email@hidden>
  • Prev by Date: Re: NSCursor changes not sticking
  • Next by Date: Strange bug with nested function
  • Previous by thread: [ANN] QSW_UUID.framework posted
  • Next by thread: Re: NSDistributedNotificationCenter question
  • Index(es):
    • Date
    • Thread