Re: Manually loading into a Core Data model
Re: Manually loading into a Core Data model
- Subject: Re: Manually loading into a Core Data model
- From: Matt Neuburg <email@hidden>
- Date: Mon, 20 Nov 2006 18:29:38 -0800
- Thread-topic: Manually loading into a Core Data model
On Mon, 20 Nov 2006 19:01:32 -0500, Karl Moskowski <email@hidden>
said:
>Hi all,
>
>I'm writing an app where I present data from a third-party XML file.
>I've got a method to manually load the XML file into managed objects,
>I've wired up the UI with Cocoa bindings and controllers, and I've
>temporarily bound it to a button for testing. It all seems to work.
>
>However, I'd like it to load automatically at application launch, so
>I'm thinking of triggering the load in the app delegate's
>applicationDidFinishLaunching method. Also, since I don't have to
>manipulate or save the loaded data, I'd like to suppress the
>automatic saving of the store to disk when the app quits, i.e., I'd
>like to reload it from the source XML file every time; for this, I'm
>using a subclass of NSManagedObjectContext, and I've overridden the
>save method to do nothing, and it seems to work.
>
>My question is, are these the right places to do these things? Is
>there a better place than applicationDidFinishLaunching to load the
>XML into the model? Is there a more appropriate way to make the
>entire store non-persistent between launches?
There is no need to subclass NSManagedObjectContext. Just modify the app
delegate provided by the template: create the persistent store coordinator
with NSInMemoryStoreType, delete all the stuff about the
applicationSupportFolder, and delete the saving code. This is really easy,
you're making it way too complicated.
And yes, applicationDidFinishLaunching is a fine place to load up your data.
You will, in that case, probably want to suppress showing your main window
until the data has loaded (because otherwise it shows up blank). You'll need
to use delayed performance after loading the data, to give the interface a
chance to reconcile itself, before you show the main window.
For example code, just download my Thucydides app. m.
--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
<http://www.amazon.com/gp/product/0596102119>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden