Re: Where to properly call [NSPersistentStoreCoordinator persistentStores] ?
Re: Where to properly call [NSPersistentStoreCoordinator persistentStores] ?
- Subject: Re: Where to properly call [NSPersistentStoreCoordinator persistentStores] ?
- From: Serg Koren <email@hidden>
- Date: Fri, 18 Aug 2006 19:24:20 -0400
Hi Chris,
I'm trying to open my document and get my persistent store so that I
can seed data to the database--I DO have a store I'm just not finding
it until after the window (MyDocument-file owner) displays.
That is on initial launch of my app, I wan to populate part of my
model with info about the user environment. No, I can't use a static
set of data, the data I'm prepopulating with happens to be the current
calendars in iCal. Every succeeding time the document is loaded I
want to sync my models contents with iCal's calendars.
I have the getCoreDataEnvironment method so that I don't have to keep
typing [myContext persistenStoreCoordinator] all over the place for
example, and it's probably faster in the long run since it gets
evaluated once...am I wrong?
[myContext persistentStoreCoordinator] for example has to be
reevaluated every time I need to get the coordinator. If I do this a
lot, it's probably more efficient to set it on persistentStore load
and just use the instance variable since they never change until
resaved. It also simplifies the code and centralizes the logic.
My problem is I don't know where the persistentStore gets loaded when
FileOwner loads.
I'm a newbie to CoreData/Cocoa. I'm more comfortable with SQL
logical/physical modeling and less so with CoreData's entity
modeling. If there is a simpler way to do what I want, let me know
please.
Cheers,
S
On Aug 18, 2006, at 5:29 PM, Chris Hanson wrote:
On Aug 18, 2006, at 1:14 PM, Serg Koren wrote:
I'm trying to get an array of persistenStores from my CoreData
Document app. I'm loading my model and trying to get the store
for the model I just loaded PRIOR to any user interaction with the
window.
What are you really trying to accomplish by doing this? That is,
what end goal will addressing this help you achieve? There may be a
better way to go about doing it. In general, a persistent
document's persistent store coordinator won't have any persistent
stores until it's saved, and then it will be associated with a
single persistent store. An opened document will be associated with
a single persistent store.
Code snippet I'm using follows from the NSPersistentDocument
subclass called from init:
-(void) getCoreDataEnvironment
{
myContext = [self managedObjectContext];
myCoordinator = [myContext persistentStoreCoordinator];
myManagedObjectModel = [myCoordinator managedObjectModel];
myEntities = [myManagedObjectModel
entitiesByName]; // works...returns 6
myPersistentStores = [myCoordinator
persistentStores]; // returns 0
}
It looks like this method just caches these values in instance
variables. Why do this, when they're already accessible to your
document code anywhere it needs them via the above methods?
-- Chris
_______________________________________________
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