Re: Implementing custom accessors in core data
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