• 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
Re: What to use observeValueForKeyPath: context
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What to use observeValueForKeyPath: context


  • Subject: Re: What to use observeValueForKeyPath: context
  • From: Ron Lue-Sang <email@hidden>
  • Date: Fri, 29 Aug 2008 09:20:38 -0700


On Aug 29, 2008, at 8:13 AM, Dave Dribin wrote:

On Aug 29, 2008, at 10:03 AM, Phil wrote:
On Sat, Aug 30, 2008 at 2:56 AM, Dave Dribin <email@hidden> wrote:
Is there some benefit to using number values over string constants, or is it
just stylistic differences?



Using NSStrings (or any other object) will work fine, but comparing two primitive numbers is a lot faster than comparing to strings.

As long as the pointers point to unique objects (and they remain valid even in a GC world), you just need to compare their pointer value. So even with this:


static NSString *PropertyObservationContext = @"Property Context";

You can still check (context == PropertyObservationContext) in observeValueForKeyPath:ofObject:change:context:.

I do this as well… sorta… My dao is usually

static NSString *ABCFooPropertyObservingContext;

observeValueFoKeyPath:
(context == &ABCFooPropertyObservingContext) that way you don't use up space for char storage. Yea, that amount of storage probably doesn't matter, but "probably" isn't "definitely" =)


I (and some coworkers) have also done plain old

static void* ABCblahblahContext;




Personally, I wouldn't use arbitary numbers for any pointer value
(even a context variable like this), but that's just my stylistic
difference.

I generally wouldn't either, unless there's some benefit I'm not seeing.


-Dave




-------------------------- RONZILLA



_______________________________________________

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


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

  • Prev by Date: Re: File Extensions Problem
  • Next by Date: Re: Quitting all active applications
  • Previous by thread: Re: What to use observeValueForKeyPath: context
  • Next by thread: Re: What to use observeValueForKeyPath: context
  • Index(es):
    • Date
    • Thread