Correct Save/Save As behavior for document imported into a Core-Data app
Correct Save/Save As behavior for document imported into a Core-Data app
- Subject: Correct Save/Save As behavior for document imported into a Core-Data app
- From: Andrew Madsen <email@hidden>
- Date: Wed, 1 Nov 2006 17:05:01 -0700
I'm developing a Core-Data based application. However, I need to be
able to import/export a certain standard data interchange format
(call it XYZ format). Export is no big deal, and in fact I've
already got it done. However, I've run into a problem with
importing. I may have gone about implementing import wrong in some
areas.
Right now, I'm overriding readFromURL:ofType:error: in MyDocument. I
check to see if the type is the same as the format I need to import
(ie. not a Core Data store), and if it is, I pass things off to a
custom method that actually does the importing. Otherwise, I just
return [super readFromURL:ofType:error:]. Opening files that are
native formats (ie Core Data stores) continues to work fine. If I
open/import an XYZ file, a new document window comes up, with all the
data as I expect it. My UI is heavily reliant on core data and
bindings, so it's clear that my import method is working. Imported/
opened XYZ data ends up in that document's Managed Object Context as
it should.
All of my problems are related to saving. When I import an XYZ file,
and then hit Save, my app crashes. That's not really unexpected, and
I don't want it to save over the imported file anyway. So, in my
import method, at the very end, I change the document's file type and
URL to a natively supported (Core-Data) XML format. However, saving
still doesn't work. If I hit Save, I get an alert sheet saying "The
location of the document "test.xml" cannot be determined. You can
specify where to save it". I presume that's because even though I've
set a URL for the document, the file it's pointing to doesn't really
exist. OK, no big deal. However, if I click Save As and tell it
explicitly where to put the file, I get an error in the console
"Exception raised during posting of notification. Ignored.
exception: nil is not a valid persistent store" I'm not entirely
sure how to deal with that error.
My first choice for behavior would be for an opened/imported XYZ
document to show up as untitled so that Save forces a Save As just
like a new, untitled but edited document does.
What is the best way to attack this problem? Is there some way to
"reset" a document to it's untitled state? Is there just something I
need to do to/with the MOC or Persistent Store Coordinator in an
imported document to get it to save properly? I'm a little lost...
Thanks for any replies,
Andrew Madsen
_______________________________________________
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