Skip navigation.
 
mlNSManagedObjects in a legacy document
FROM : Drew McCormack
DATE : Sun Jul 02 17:54:02 2006

I've got a legacy Cocoa app that uses keyed-archiving for 
persistence. I do not want to convert the existing model classes to 
Core Data at this point, but I am extending the app with a piece of 
completely new code. I would like to use CoreData for the new code, 
and embed the managed objects in the current legacy document format.

What I don't want to do is add keyed-archiving methods to my 
NSManagedObjects; this seems wasteful, because all the knowledge to 
archive the objects is already present in the form of the model. What 
I want is that when my document is saved, a few calls to CoreData are 
made to convert that part of the object graph into raw data, so that 
I can then just add that via keyed-archiving methods to the legacy 
document.

So I want a simple way to convert a bunch of NSManagedObjects from an 
NSManagedObjectContext into NSData. I thought maybe I could use an in 
memory store to do this, but I can't see any way to archive objects.

My only proposal at this time is to setup a temporary file-based 
persistent store, save the object graph, and then simply read in the 
file as data and add that to the document. Seems a bit roundabout, 
but that is all I can think of.

Is there a better approach?

Drew

Related mailsAuthorDate
No related mails found.