• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Core Data: Copying and pasting chained entities
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Core Data: Copying and pasting chained entities


  • Subject: Re: Core Data: Copying and pasting chained entities
  • From: Ben Trumbull <email@hidden>
  • Date: Mon, 6 Oct 2008 19:41:46 -0700

Renaud,

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.

That's correct. Managed objects do not conform to NSCoding.

However, a similar mechanism must exist, because Core Data stores and
fetches entities.

Not in a fashion that's meaningful to copy&paste. The atomic stores (xml, binary) write everything (e.g. whole file) out all the time. The incremental sqlite store only saves deltas. Neither is helpful for the pasteboard.


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.

There are a few examples floating around. Typically, you need the NSManagedObjectID and a snapshot of the attributes. Both KVC and NSManagedObject have methods to grab a bunch of keys at once to simplify this.


Relationships are an issue, because there is no one answer. Do you want a shallow copy or a deep copy ? How deep ? The related objects' related objects ? Most people settle for a mix of references and copies.

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.

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.

- Ben

_______________________________________________

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


  • Follow-Ups:
    • Re: Core Data: Copying and pasting chained entities
      • From: Renaud CĂ©roce <email@hidden>
  • Prev by Date: [MEET] Minnesota CocoaHeads 10/9/08
  • Next by Date: Re: performSelectorOnMainThread Help
  • Previous by thread: [MEET] Minnesota CocoaHeads 10/9/08
  • Next by thread: Re: Core Data: Copying and pasting chained entities
  • Index(es):
    • Date
    • Thread