Re: Core data dependent attributes
Re: Core data dependent attributes
- Subject: Re: Core data dependent attributes
- From: Sean Murphy <email@hidden>
- Date: Fri, 26 May 2006 15:07:28 -0400
On May 26, 2006, at 2:32 PM, Matteo Manferdini wrote:
Hi everyone. I have a data model in core data in which an object
has a numeric attribute that depends on some calculations on
attributes of objects in a to many relationships. I need to keep
this attribute up to date.
If I were using a standard object I know I would have to use KVO,
but I don't know how to do this in core data's managed objects.
Since this attribute depends solely on other attributes, I don't
need to save it. Looking at core data's docs, I think I have to
implement a custom accessor method to compute the value. Is this
right?
Moreover, can I use KVO in managed objects, so when the attributes
change the derived attribute will change as well? (somethin like
"Registering dependent keys" in KVO programming guide http://
developer.apple.com/documentation/Cocoa/Conceptual/
KeyValueObserving/Concepts/DependentKeys.html but using attributes
of other objects).
One last question: core data programming guide states that I can
use the Xcode data modeling tool to generate the code for accessor
methods for any modeled property. How can I exactly do this?
Hey Matteo,
I'm not sure if this will answer your question, but the FAQ in the
"Core Data Programming Guide," addresses this issue:
http://developer.apple.com/documentation/Cocoa/Conceptual/CoreData/
Articles/cdFAQ.html#//apple_ref/doc/uid/TP40001802-DontLinkElementID_19
Also, if you'd like to use custom accessor methods, here's the way to
get the data modeling tool to generate the declarations and
implementations (in the same way that Accessorizer does):
Either using the Model Browser, or the Entity Graph directly, select
the attributes you want to make accessor methods for. Then in the
Xcode menu, choose Design > Data Model > Copy Method Declarations
(and Implementations) to Clipboard. The just paste them into your
subclass of NSManagedObject.
Important to note is that you don't have to formally declare the
variables themselves, Core Data will take care of that. You just
need to declare what methods your subclass will respond to.
For more info on custom accessor methods of NSManagedObject: http://
developer.apple.com/documentation/Cocoa/Conceptual/CoreData/Articles/
cdMemory.html#//apple_ref/doc/uid/TP40001860.
Hope that helps!
-Murph
_______________________________________________
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