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:27:04 -0400
On Fri, Aug 29, 2008 at 10:56 AM, Dave Dribin <email@hidden> wrote:
> Hi all,
>
> It seems that KVO best practice is to use the "context" in
> observeValueForKeyPath:ofObject:change:context: to differentiate between
> different key paths, rather than check key path strings for equality. Since
> context is a void *, it also seems best practice to just use some unique
> pointer values. For example, mmalc's Graphics Bindings sample does this:
>
> static void *PropertyObservationContext = (void *)1091;
> static void *GraphicsObservationContext = (void *)1092;
> static void *SelectionIndexesObservationContext = (void *)1093;
>
> I'm not quite understanding the point of using number values like this,
> though. Won't using unique string literals (char * or NSString *) also
> work?
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.
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