• 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: Implementing custom accessors in core data
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Implementing custom accessors in core data


  • Subject: Re: Implementing custom accessors in core data
  • From: Chris Hanson <email@hidden>
  • Date: Wed, 18 Jan 2006 09:22:40 -0800

On Jan 18, 2006, at 6:25 AM, Knud Möller wrote:

I wonder: why can't I just implement convenience accessor methods like this:

- (NSString *)name
{
    return [self valueForKey: @"name"];
}

- (void)setName: (NSString *)name
{
    [self setValue: name forKey: @name];
}

Would this work?

No.

Or does the existence of custom accessors prevent the valueForKey/ setValueForKey methods from working properly?

No, the issue is that -valueForKey: and -setValue:forKey: when passed the key @"name" will invoke your -name and -setName: methods.


The high-level KVC methods will call your methods if present, which should in turn wrap KVO notifications around calls to the primitive KVC methods just as the Core Data documentation and sample code shows.

  -- Chris

PS - The proper names of the methods are -valueForKey: and - setValue:forKey:. Colons are part of the method/selector name in Objective-C, and the leading "-" signifies an instance method (a leading "+" signifies a class method).

_______________________________________________
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: 
 >Implementing custom accessors in core data (From: Knud Möller <email@hidden>)

  • Prev by Date: NSAttributedString - determine document type without loading?
  • Next by Date: Re: Distributed Object, exception failure not handled properly
  • Previous by thread: Re: Implementing custom accessors in core data
  • Next by thread: NumberFormatters and sci notation
  • Index(es):
    • Date
    • Thread