Re: Core Data: Copying and pasting chained entities (Renaud C?roce)
Re: Core Data: Copying and pasting chained entities (Renaud C?roce)
- Subject: Re: Core Data: Copying and pasting chained entities (Renaud C?roce)
- From: Renaud CĂ©roce <email@hidden>
- Date: Thu, 02 Oct 2008 14:10:09 +0200
Hi Daniel, thanks for answering,
I guess my question was unclear, so I'm going to sum it up: How do I (with
Core Data) implement Copying and pasting within my application ?
Your message made me realise that I assumed I had to use the system
Pasteboard. But as long as data remains within my application, I obviously
do not have to.
Now back to the solution you propose: it won't provide the expected
behaviour. Let me explain, and you shall understand what my question is all
about:
When the figure is copied, I can not put it in the managed object context.
Why ? Because the copied figure would be saved on disk. The application
must wait for the user to paste the figure before inserting it in the
managed object context. So it really ought to save the figure and the
associated entities somewhere else (in an other managed object context ?
Maybe).
>From what I read, without Core Data, copying is usually implemented using
NSArchiver. Each object (Figure, FillStyle, FillColor) implements the
encodeWithCoder: method, so it can choose what properties matter, and copy
them to the archive. An interesting point is the relationships among the
objects are stored in the archive too, and every objects referenced by the
root object either directly or indirectly will have its encodeWithCoder:
method called. The NSArchiver's data is then put to the pasteboard.
Pasting is the same, the other way round: NSUnarchiver instantiates the
objets and calls their initWithCoder: method so they can set their
properties.
Now, I am nearly sure that I cannot use the NSArchiver/NSUnarchiver with
NSManagedObjects, because NSArchiver/NSUnarchiver know nothing about Core
Data relationships and because NSUnarchiver won't know how to insert an
object in the managed object context.
However, a similar mechanism must exist, because Core Data stores and
fetches entities.
So once again: how do you implement copy and paste with Core Data ? It is a
common operation; I was very surprised not to find any article on the
subject.
Renaud Pradenc
--------------
ceroce.com
On Wed, 01 Oct 2008 10:44:51 -0400, Daniel Child <email@hidden> wrote:
> I'm not sure if I understand your question, but if FillStyle and
> FillColor are entities, why not simply create corresponding managed
> objects and set their values, making sure that all of the relations
> (between color and style, and between style and figure) are
> established. They will then be automatically stored in the persistent
> store like any other managed object. As far as I can tell, there is no
> need to use archiving unless you want to prepare in a special format
> for another application.
>
_______________________________________________
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