Re: How to load from templates like in iWork using CoreData?
Re: How to load from templates like in iWork using CoreData?
- Subject: Re: How to load from templates like in iWork using CoreData?
- From: "E. Wing" <email@hidden>
- Date: Wed, 12 Oct 2005 14:58:23 -0700
> Add (with the read-only option) the persistent store that represents
> your template. Then use -[NSPersistentStoreCoordinator
> migratePersistentStore:toURL:options:withType:error:] to generate the
> persistent store that represents your actual document.
>
> If you want to avoid creating a file for your new document
> immediately, you can migrate to an in-memory persistent store from
> the template,
Thank you for your reply. I have made a little bit of progress, but
there are still some things that I am not doing right.
So you said to first add the persistent store that represents my
template. To clarify, should I use
addPersistentStoreWithType:configuration:URL:options:error for this?
And then I should pass the store that is returned by this method as
the store for migratePersistentStore:toURL:options:withType:error:?
If this is correct, I'm having a few problems with this. For
clarification, I am interested the "avoid creating a file for your new
document immediately" behavior you suggested. This is a code snippit
of what I have.
NSDictionary* store_options_dict = [NSDictionary
dictionaryWithObject:[NSNumber numberWithBool:YES]
forKey:NSReadOnlyPersistentStoreOption];
NSPersistentStoreCoordinator* persistent_store_coordinator = [[self
managedObjectContext] persistentStoreCoordinator];
template_store = [persistent_store_coordinator
addPersistentStoreWithType:NSXMLStoreType configuration:nil
URL:template_url options:store_options_dict error:&error];
migrate_store = [persistent_store_coordinator
migratePersistentStore:template_store toURL:nil
options:store_options_dict withType:NSInMemoryStoreType error:
&error];
There are 2 immediate problems with the code when I run it. First, the
dictionary options I pass into addPersistentStoreWithType are
triggering errors in my console:
005-10-12 14:30:05.551 MismatchExport[21930] *** -[NSCFDictionary
executeRequest:withContext:]: selector not recognized [self =
0x3e8ef0]
2005-10-12 14:30:05.551 MismatchExport[21930] Exception raised during
posting of notification. Ignored. exception: *** -[NSCFDictionary
executeRequest:withContext:]: selector not recognized [self =
0x3e8ef0]
2005-10-12 14:30:05.553 MismatchExport[21930] Can't save store to
(null) (read-only store)
This dictionary option only seems to be a problem for
addPersistentStoreWithType because I do not get an error with these
options with migratePersistentStore. If I change the option to nil for
addPersistentStoreWithType, the errors go away. But I'm not sure if
this is correct.
My other problem is that I do not see any values in my UI.
To verify this code is doing anything, I modified my code to create
the new document file immediately to see what would happen.
template_store = [persistent_store_coordinator
addPersistentStoreWithType: NSXMLStoreType configuration:nil URL:
template_url options: nil error: &error];
migrate_store = [persistent_store_coordinator migratePersistentStore:
template_store toURL: migrate_url options: store_options_dict
withType: NSXMLStoreType error: &error];
In this case, I can see a file created which seems to contain all my
data from my template store which is good. But my UI is still
completely blank. So what piece am I missing to get my UI to reflect
the data?
> and then upon document save you can migrate that in-
> memory store to a persistent store on disk.
>
Finally, once I do get the other stuff working, can you elaborate on
what I need to do for this part? I'm presuming that I will need to
override some methods? Do you know which ones I should look at? And in
these methods, will I just be calling migratePersistentStore again? If
so, I presume I only want to migrate for new documents and "Save As"
situations. How would I (or would I need to) distinguish between
NewDocs/SaveAs vs files that were loaded?
Thanks,
Eric
_______________________________________________
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