Core Data Confusion
Shawn Erickson
shawnce at gmail.com
Mon Feb 5 09:11:10 PST 2007
On 2/5/07, Marcus S. Zarra <mzarra at mac.com> wrote:
> The KVO methods do not fire faults in Core Data. Core Data retrieves
> all of the values for a managed object when that object is accessed.
> It specifically does not do any lazy initialization of attributes.
> However, it does do lazy initialization of relationships.
>
> The primitive methods will cause a fault to fire on a lazy
> relationship. If you access another managed object via -
> primitiveValueForKey: and that object has not been loaded yet -- the -
> primitiveValueForKey: method will cause it to fire. This can be
> tested very easily.
>
> The -willChangeValueForKey: and -didChangeValueForKey: should be
> wrapped around any calls to primitive setters -- not getters.
...and folks are talking about will/didAccessValueForKey: [1].
For example...
- (Measure *)measure {
id tmpObject;
[self willAccessValueForKey: @"measure"];
tmpObject = [self primitiveValueForKey: @"measure"];
[self didAccessValueForKey: @"measure"];
return tmpObject;
}
- (void)setMeasure:(Measure *)value {
[self willChangeValueForKey: @"measure"];
[self setPrimitiveValue: value forKey: @"measure"];
[self didChangeValueForKey: @"measure"];
}
[1] <http://developer.apple.com/documentation/Cocoa/Reference/CoreDataFramework/Classes/NSManagedObject_Class/Reference/Reference.html#//apple_ref/occ/instm/NSManagedObject/didAccessValueForKey:>
More information about the MacOSX-dev
mailing list