Re: Core Data: Copying and pasting chained entities
Re: Core Data: Copying and pasting chained entities
- Subject: Re: Core Data: Copying and pasting chained entities
- From: Renaud CĂ©roce <email@hidden>
- Date: Wed, 08 Oct 2008 08:31:51 +0200
Hi ben,
On Mon, 6 Oct 2008 19:41:46 -0700, Ben Trumbull <email@hidden> wrote:
> There are a few examples floating around.
>
Could you point me at those articles ? I was not able to find them.
> Typically, relationships are stored externally as either references
> (NSManagedObjectID in URI form) or copies (e.g. all their
> attributes). Just how far you copy the object graph is up to you.
>
I've just written a few classes to copy the graph. The solution I came with
is similar to the one exposed in the Persistent Document tutorial: Make up
a dictionary that associates the attributes names with their values. For
the relationships: associate their name with a dictionary representing the
associated object, and so on. Finally, the dictionaries are turned into an
NSData using NSArchiver.
However, my solution has an issue: it works when objects are organised in a
tree structure, but it will loop indefinitely if a relationship makes a
managed object point at itself. Whereas NSArchiver has a mechanism to avoid
that.
It's okay for my needs anyway.
> Some apps don't copy the graph at all, and just put a reference (URI)
> on the pasteboard and when it's pasted back, look up the object.
>
Yes, it is a simple solution, but I guess it can rarely be used. If you
Copy an object, modify the object, then Paste, the pasted object will be
like the modified object, not like the original one.
I thought about an other solution: do you think we could create an other
NSManagedObjectContext and copy the graph to it ? It did not seem like one
can create a NSManagedObjectContext easily, so I did not investigate
further; but do you think it is feasible ?
Thank you a lot for you answer anyway !
Renaud Pradenc
--------------
ceroce.com
_______________________________________________
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