Core Data: custom model object accessors vs. KVC
Core Data: custom model object accessors vs. KVC
- Subject: Core Data: custom model object accessors vs. KVC
- From: Ryan Homer <email@hidden>
- Date: Thu, 25 Jan 2007 16:48:33 -0500
According to Core Data Programming Guide -> Using Managed Objects ->
Accessing and Modifying Properties:
"To access or modify properties of a managed object, by default you
use key-value coding, "...
Ex: NSString *firstName = [newEmployee valueForKey:@"firstName"];
However, when creating a custom managed object according to the Low-
Level Core Data Tutorial -> Implementing the Managed Object Subclass -
> Implementing the Accessor Methods:
"When you implement custom accessors for a managed object class, you
must ensure you invoke the appropriate access and change notification
methods."
Ex:
- (NSDate *)date
{
[self willAccessValueForKey:@"date"];
id date = [self primitiveValueForKey:@"date"];
[self didAccessValueForKey:@"date"];
return date;
}
So, my questions are:
(1) Is it ok to use valueForKey: in the custom class instead of
primitiveValueForKey: and therefore not use willAccessValueForKey:
and didAccessValueForKey:
(2) What exactly is the difference between them? According to the docs,
primitiveValueForKey:
Returns from the receiver’s private internal storage the value for
the specified property.
valueForKey:
Returns the value for the property specified by key.
but I'm still not clear on the difference. If a fetch is returning
data from the persistent store into an array, why should I be using
primitiveValueForKey and digging into the private internal storage?
Thanks in advance for your replies.
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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