Re: What to use observeValueForKeyPath: context
Re: What to use observeValueForKeyPath: context
- Subject: Re: What to use observeValueForKeyPath: context
- From: "Michael Ash" <email@hidden>
- Date: Fri, 29 Aug 2008 12:56:26 -0400
On Fri, Aug 29, 2008 at 12:41 PM, Dave Dribin <email@hidden> wrote:
> On Aug 29, 2008, at 11:27 AM, Michael Ash wrote:
>>
>> This (void *)1091 business seems highly dangerous to me. After all,
>> what prevents somebody else from using 1091 too? If everybody uses a
>> pointer value that's guaranteed to be unique (like a unique string
>> literal) then you know you're safe.
>
> It really just needs to be unique in your class hierarchy, right?
True, but not particularly useful. Your class hierarchy includes
NSObject, which is free to observe whatever it feels like in your
objects.
> I'm liking Ron's way, because that's guaranteed to be a unique pointer
> value. I still like the static string, too, but it sounds like in order to
> ensure uniqueness of the string within a class hierarchy, it may be a good
> idea to put the class name in there. Two classes using static @"Property
> Context" should still be unique, unless the linker does some cross-module
> string literal optimization so that there's only a single @"Property
> Context" string literal in the entire binary. I don't think it does now,
> but perhaps with LLVM it'll do more aggressive optimizations like this.
I agree. If you use a constant string, you should make sure that the
string *contents* are unique, in order to ensure uniqueness of the
pointer to it. So don't call it @"context", use @"MyFunkyClass KVO
observer context". After all there's no penalty for being verbose in
this case. Of course using a pointer to a global solves this too.
Mike
_______________________________________________
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