Is this a bug, or am I hacking?
Is this a bug, or am I hacking?
- Subject: Is this a bug, or am I hacking?
- From: Graham Cox <email@hidden>
- Date: Thu, 14 Aug 2008 21:55:27 +1000
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?
cheers, Graham
_______________________________________________
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