Re: Is this a bug, or am I hacking?
Re: Is this a bug, or am I hacking?
- Subject: Re: Is this a bug, or am I hacking?
- From: Keary Suska <email@hidden>
- Date: Thu, 14 Aug 2008 10:19:51 -0600
- Thread-topic: Is this a bug, or am I hacking?
8/14/08 5:55 AM, also sprach email@hidden:
> I have some UI that manages a data model that can store two kinds of
> objects. The data management of the objects is identical but the
> actual objects themselves are fairly distinct. One of the things I'm
> trying to do is to allow my data management UI to update "live" if a
> change is made to the actual object currently displayed. To do this,
> I'm making use of notifications ("object changed"). Works OK as far as
> it goes.
>
> Here's the hack. The two object classes define different strings for
> the "did change" notification, but my UI management code would prefer
> not to care about what actual object type is in use. So I made the
> literal string constant for one object's message the same as the
> string constant for the other class. As hacks go it's probably fairly
> mild as they both mean much the same and the two object types are
> unlikely to get confused with each other elsewhere.
>
> But here's what I find. Only notifications from one of the classes is
> actually received. So what I think must be happening is that when
> NSNotificationCenter decides what messages to dispatch to its
> observers, it's only comparing the message name string by address, not
> using -isEqual: or -isEqualToString:, so no match is detected, even
> though the strings are the same. Ah, but aren't identical literal
> string constants coalesced when compiled? Usually, I think that's
> true, but one of these is in a linked framework and the other is local
> to my app, so this is not happening. So should the comparison of the
> notification name by address be considered a bug? Or have I guessed
> wrong about what's going on?
If I understand your issue correctly, I think you're barking up the wrong
tree. In my testing, Ic an do:
NSString *name = [NSString stringWithFormat:@"%@DidChange", @"Dict"];
NSLog(@"Note name address: %p", name);
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didChangeNote:) name:name object:nil];
2008-08-14 10:13:21.375 Tester[4724:813] Note name address: 0x141270
and if I do:
NSString *noteName = @"DictDidChange";
NSLog(@"Note name address: %p", noteName);
[[NSNotificationCenter defaultCenter] postNotificationName:noteName
object:self];
2008-08-14 10:13:21.358 Tester[4724:813] Note name address: 0x304c
I receive the notification properly, and I can confirm that the notification
name is a different object in each case.
Or do I misunderstand?
HTH,
Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden