Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What to use observeValueForKeyPath: context



On Aug 29, 2008, at 10:56 AM, Dave Dribin wrote:

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;

Your KVO context has to be unique.

If you use 1091, there is no way to guarantee that any of your subclasses or superclasses aren't also using that magic number, so this sets you up for possible failure.

Jim

_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >What to use observeValueForKeyPath: context (From: Dave Dribin <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.