RE:Core Data: where is the default store in a CD-Document-Based-App?
RE:Core Data: where is the default store in a CD-Document-Based-App?
- Subject: RE:Core Data: where is the default store in a CD-Document-Based-App?
- From: Ron Lue-Sang <email@hidden>
- Date: Tue, 23 Aug 2005 11:13:09 -0700
Date: Tue, 23 Aug 2005 15:04:02 +0100
From: Peter Laurens <email@hidden>
Subject: Core Data: where is the default store in a
CD-Document-Based-App?
To: email@hidden
Message-ID: <email@hidden>
Content-Type: text/plain; charset=US-ASCII; delsp=yes;
format=flowed
Hi,
I'm building my first Core Data app, so be gentle ;)
Problem:
------------
I had a relatively simple Core Data Document Based App all set up.
Naturally XCode sets me up a decent starting point, and I just draw
my data model and everything is handled for me. This was great - and
obviously there's a persistent store set up automagically for me,
because I can save my data in my app without any work. Well - I say
'obviously' but this is an assumption because... I can't seem to
'find this original persistent store...
I do :
- (void)windowControllerDidLoadNib:(NSWindowController *)
windowController
{
NSPersistentStoreCoordinator *documentStoreCoordinator = [[self
managedObjectContext] persistentStoreCoordinator];
NSLog(@"Number of stores is %d", [[documentStoreCoordinator
persistentStores]count]);
}
In MyDocument, and NSLog prints '0'. Whereas I would expect it to say
'1'. Because there's something there saving my stuff (unless I'm
imagining things).
If the document hasn't been saved yet, this is what would happen.
You
Why do I want to know about this?:
-----------------------------------------------
Well, I'd like to know more about this 'default' automagic store
because as my app progressed I had need to create an in-memory store
for a certain type of object that I don't need to save. That was all
very simple to do.
But seems to have thrown my app a bit of a wobbly.
After I create the in-memory store ([documentStoreCoordinator
addPersistentStoreWithType:NSInMemoryStoreType configuration:nil
URL:nil options:nil error:&error];) nothing gets saved when I call
the 'save' command from the File menu in my app.
So I assume that everything is going, by default, into the in-memory
store. Which has taken precedence for use over the 'default' original
store that was used before I started messing with the persistent
stores in code.
Yes, chances are...
So I'd like a way to call assignObject:toPersistentStore: and assign
all things I want to whatever it is that's set up to store my things
for me in a fresh Core Data app (the store I can't manage to 'find')
- if that makes sense.
It'd probably be easiest for you to override
- (BOOL)configurePersistentStoreCoordinatorForURL:(NSURL *)url ofType:
(NSString *)fileType error:(NSError **)error {
and call super before asking context.coordinator for its
persistentstores.
Another thought is, you don't have relationships between the objects
your saving and your special in memory object, right? Why not keep
the special object in its own coordinator as well?
One thing I did try was just to create another store to handle the
stuff that needs to be saved - duplicating the automatically provided
CD-Document-Based-App functionality by making my own persistent store
for stuff to save, as WELL as the in-mem store for stuff I didn't
want saved. This had me quickly tying myself in knots because such a
store needs an URL for its store - and in a document based app I'll
need to manually make a different URL for each store to make sure
documents don't step on each other's stores, and handle the cleanups
etc. etc. etc. Well... it just seemed like a totally wrong and non-
Cocoa thing to do.
@finally:
------------
All simple stuff for many of ya I'm sure. But any help offered on
getting my head around these issues would be so very gratefully
received...
Thanks in advance!
- Pete
-----------------------------
Ronzilla
Core Bindings/Cocoa Data
_______________________________________________
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