• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
What to use observeValueForKeyPath: context
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

What to use observeValueForKeyPath: context


  • Subject: What to use observeValueForKeyPath: context
  • From: Dave Dribin <email@hidden>
  • Date: Fri, 29 Aug 2008 09:56:11 -0500

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?

static NSString *PropertyObservationContext = @"Property Context";
static NSString *GraphicsObservationContext = @"Graphics Context";
static NSString *SelectionIndexesObservationContext = @"Selection Indexes Context";


Is there some benefit to using number values over string constants, or is it just stylistic differences?

Thanks,

-Dave

_______________________________________________

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


  • Follow-Ups:
    • Re: What to use observeValueForKeyPath: context
      • From: mmalc crawford <email@hidden>
    • Re: What to use observeValueForKeyPath: context
      • From: Jim Correia <email@hidden>
    • Re: What to use observeValueForKeyPath: context
      • From: "Michael Ash" <email@hidden>
    • Re: What to use observeValueForKeyPath: context
      • From: Phil <email@hidden>
  • Prev by Date: RE: Convert unicode string into ascii
  • Next by Date: Re: What to use observeValueForKeyPath: context
  • Previous by thread: Path animation with CGPathAddArcToPoint
  • Next by thread: Re: What to use observeValueForKeyPath: context
  • Index(es):
    • Date
    • Thread