• 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
When to use key-value coding to get values vs. accessors
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

When to use key-value coding to get values vs. accessors


  • Subject: When to use key-value coding to get values vs. accessors
  • From: Paul Bruneau <email@hidden>
  • Date: Thu, 1 Nov 2007 16:29:02 -0400

Hi-

Not looking for an in-depth explanation (I should be able to find/ understand the docs once I get tipped in the right direction), but can someone briefly hint to me the reason Apple uses key-value coding in this example code:

- (NSString *)fullNameAndID
{
    return [NSString stringWithFormat:@"%@, %@ (%@)",
            [self valueForKey:@"lastName"],
            [self valueForKey:@"firstName"],
            [self valueForKey:@"employeeID"]];
}


the example comes from
http://developer.apple.com/documentation/Cocoa/Conceptual/ NSPersistentDocumentTutorial/03_CustomClass/chapter_4_section_3.html


Is there any advantage over doing it how I would tend to think to do it?:

- (NSString *)fullNameAndID
{
    return [NSString stringWithFormat:@"%@, %@ (%@)",
            [self lastName],
            [self firstName],
            [self employeeID]];
}

It must be because using -valueForKey: triggers something somewhere but I don't quite have a handle on what. Is it better Cocoa practice to just always use valueForKey? Or do I have to keep track in my head on an object by object (or even accessor by accessor) basis when it should be used? _______________________________________________

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: When to use key-value coding to get values vs. accessors
      • From: mmalc crawford <email@hidden>
  • Prev by Date: Re: Xcode 3.0 delay
  • Next by Date: Re: [Leopard] GM Build Number?
  • Previous by thread: Re: [Leopard] GM Build Number?
  • Next by thread: Re: When to use key-value coding to get values vs. accessors
  • Index(es):
    • Date
    • Thread