Re: NSDistributedNotificationCenter question
Re: NSDistributedNotificationCenter question
- Subject: Re: NSDistributedNotificationCenter question
- From: David Remahl <email@hidden>
- Date: Sun, 8 Jun 2003 17:55:56 +0200
You are not alone in having this problem:
http://cocoa.mamasam.com/COCOADEV/2002/01/1/21243.php
http://cocoa.mamasam.com/MACOSXDEV/2001/10/1/13579.php
No replies to either post, though.
I believe this is a bug in the framework, and should be reported. As
for a workaround, I guess you will have to use userInfo.
/ regards, David
svndagen den 8 juni 2003 kl 17.15 skrev Ronald Oussoren:
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.
_______________________________________________
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.