Re: NSDistantObject in Core Data
Re: NSDistantObject in Core Data
- Subject: Re: NSDistantObject in Core Data
- From: Quincey Morris <email@hidden>
- Date: Thu, 13 Nov 2008 01:25:09 -0800
On Nov 12, 2008, at 23:53, Bridger Maxwell wrote:
I am creating a server in which I would like to somehow add a
relationship
to an NSDistantObject in my Core Data object graph. I know
NSDistantObjects
can't be archived. I will have an an array of all of the live
NSDistantObjects in my application, I just need to relate them to
entities
in Core Data. Perhaps NSDistantObject instances have a unique
identifier I
can store in the data graph and use as a key to retrieve the live
instance?
For this I have considered the hash function or using the actual
pointer
value. However, I am not sure if either are very safe.
On a related note, I obviously wouldn't want these references to
NSDistantObjects to be saved to the persistent store. Is there a way
to mark
an entity in Core Data as temporary so they are not saved or restored?
One answer is to use a transient attribute to represent the
relationship. Set the attribute's "kind" to Undefined, and use a
custom NSManagedObject subclass. Define an instance variable in the
subclass to hold the actual NSDistantObject pointer, and write custom
accessors to get and manipulate its value:
http://developer.apple.com/documentation/Cocoa/Conceptual/CoreData/Articles/cdAccessorMethods.html#/
/apple_ref/doc/uid/TP40002154-SW14
If you need a to-many relationship, the instance variable can be a
NSSet* instead.
Then, add awakeFromInsert/awakeFromFetch methods to the entity's
custom class to set up the initial relationship (give a suitable
starting value to the instance variable).
That's the short version -- hope it makes sense.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please 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