Where do I define awakeFromFetch?
Where do I define awakeFromFetch?
- Subject: Where do I define awakeFromFetch?
- From: Charles Haron <email@hidden>
- Date: Tue, 19 Jul 2005 09:48:35 -0600 (GMT-06:00)
Hello All,
I created an application from "Core Data Application" template. I
created my entity with the data modeler, and then dragged the entity to
my main window in Interface Builder, which automatically created the
interface for my data access.
I have an entity that has an attribute called price, and a transient attribute called
finalPrice. I want to set finalPrice to be a percentage of price. I
I know from the documentation I want to use awakeFromFetch and
setPrimitiveValue:forKey: (see below)
I know that awakeFromFetch is a method of NSManagedObject. However,
when I do search of all files in the project, I find no references any
NSManagedObject. So the question now becomes, where do I define
awakeFromFetch?
***
awakeFromFetch
- (void)awakeFromFetch
Invoked automatically by the Core Data framework after the receiver has
been fetched or unfaulted.It is commonly used for computing derived
values or for recreating transient relationships from the receiver's
persistent properties. Subclasses should invoke super's
implementation before performing their own initialization.
If you want to compute a derived attribute in this method, you use
setPrimitiveValue:forKey: to set the attribute's value-using the
primitive accessor ensures that the managed object context does not
record any unsaved changes.
***
***
setPrimitiveValue:forKey:
- (void)setPrimitiveValue:(id)value forKey:(NSString *)key
Sets the value of the property specified by key to value in the
receiver's private internal storage. If key identifies a to-one
relationship, relates the object specified by value to the receiver,
unrelating the previously related object if there was one. Given a
collection object and a key that identifies a to-many relationship,
relates the objects contained in the collection to the receiver,
unrelating previously related objects if there were any.
Subclasses should not override this method.
This method does not invoke the change notification methods
(willChangeValueForKey: and didChangeValueForKey:). It is typically
used by subclasses that implement custom accessor methods that need
direct access to the receiver's private internal storage. It is also
used by the Core Data framework to initialize the receiver with values
from a persistent store or to restore a value from a snapshot.
This method is typically used only for modifying attributes (usually
transient), not relationships. If you try to set a to-many relationship
to a new NSMutableSet, it will (eventually) fail. In the unusual event
that you need to modify a relationship using this method, you first get
the existing set using primitiveValueForKey: (you should ensure the
method does not return nil), create a mutable copy, and then modify the
copy-as illustrated in the following example:
***
_______________________________________________
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