Re: Subclassing NSManagedObject
Re: Subclassing NSManagedObject
- Subject: Re: Subclassing NSManagedObject
- From: Fritz Anderson <email@hidden>
- Date: Sun, 22 May 2005 17:46:33 -0500
On 22 May 2005, at 5:01 PM, T Reaves wrote:
For my accessors & mutators, do I really need to go through all
the steps as outlined in Apple's docs? If they are simple
accessors & mutators, can I do
- (NSString *)name
{
return [self valueForKey:@"name"];
}
- (void)setName:(NSString *)newName
{
[self setValue:newName forKey:@"name"];
}
Shriek. Review Key-Value Coding. The key-value method valueForKey: is
implemented so that [self valueForKey: @"name"] will result in a call
to the name method. Which you define here as [self valueForKey:
@"name"]. Difficulties ensue. The same problem (filling in the
blanks) applies to setValue:forKey:.
willAccessValueForKey:/primitiveValueForKey:/didAccessValueForKey:
are recommended not just to antagonize you, but because they are
necessary. The will/didAccess methods assure you the object store is
in a consistent state while you access it, and the primitive accessor
does a direct-to-the-store access that avoids the kinds of loops seen
above.
-- F
_______________________________________________
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