• 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: ADC Core Data article
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ADC Core Data article


  • Subject: Re: ADC Core Data article
  • From: Scott Ellsworth <email@hidden>
  • Date: Sat, 9 Apr 2005 00:39:48 -0700


On Apr 8, 2005, at 2:13 PM, mmalcolm crawford wrote:

On Apr 8, 2005, at 12:48 PM, Scott Ellsworth wrote:

If foo has no "blob" accessor, then [foo blob] throws a warning at compile time, while [foo valueForKey:@"blob"] does not, instead erroring at runtime.

A strategy *some*(*) EOF developers found useful was to define string constants for the keys, so instead of valueForKey:@"blob" you would have:

Class.h

    extern NSString *blobKey;

Class.m

    NSString *blobKey = @"blob";

then [foo valueForKey:blobKey];

You could also make the key name more specific to a given entity to avoid namespace collisions etc...

Thanks for the tip. We do something like this in our current persistence code, which has something very much like valueForKey underneath, but typed accessors visible to the user. Whether it is good Cocoa style, I am not yet qualified to comment on.


This is purely a tool problem - they could write something to check valueForKey at runtime, but they have not done so,

I'm not sure what this means?

Sorry, said runtime rather than compile time. I should have said:

"In many circumstances, the key strings sent to valueForKey could be validated at _compile_ time, allowing a warning if they did not reflect either an accessor method or an underlying property."

That said, Evan DiBiase pointed out some fundamental flaws in such a tool: it could be horked up via a runtime-loaded category. It could also be plammed by isa-swizzling, or the like. It could be wrecked completely if you implement valueForKey yourself.

The common case of "is there a property or an accessor with the appropriate name", though, could be covered. This would catch the biggest single class of problems I have had with using kvc.

Scott
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Re: ADC Core Data article (From: Philippe Mougin <email@hidden>)
 >Re: ADC Core Data article (From: Shawn Erickson <email@hidden>)
 >Re: ADC Core Data article (From: Charlton Wilbur <email@hidden>)
 >Re: ADC Core Data article (From: Scott Ellsworth <email@hidden>)
 >Re: ADC Core Data article (From: mmalcolm crawford <email@hidden>)

  • Prev by Date: Re: ADC Core Data article (was: Re: Cocoa-dev Digest, Vol 2, Issue 490)
  • Next by Date: Re: ADC Core Data article
  • Previous by thread: Re: ADC Core Data article
  • Next by thread: Re: ADC Core Data article
  • Index(es):
    • Date
    • Thread