I think maybe my explanation could be clearer. Here's the flow:

1. User initiates import of file of type "fred"
2. I pick that up in -readFromURL:ofType:error:, and spawn a process which 
converts files of type "fred" to type "myfiletype", the native file type of the 
application. Let's say that it is stored in a file called 
/MyImports/file.mytype.
3. Still in -readFromURL:ofType:error:, I call super, telling it to load the 
converted file, and then call [self setFileURL:nil]; [self 
setFileType:@"myfiletype"];

Result at this stage is that the file is open and displaying normally. Then the 
user saves the file:

1. saveToURL:... is called with the file name the user gave in the save panel.
2. writeToURL:... is called with the file name set to the new name, but in a 
temporary folder "(A Document Being Saved By myapplication)". This is the 
normal document saving process, and an empty file is created.
3. core data reads the empty file, and updates the cache nodes from the managed 
objects. All normal.
4. Now here is where the problem arises: core data now writes the data out to 
the file that was originally opened: /MyImports/file.mytype. The empty file has 
empty data written back to it.
5. The document architecture completes the save operation by moving the file 
(with no data in it) to the location the user said to save it to.

Now if this was a normal "open and save as" operation, step 4 would have 
written the data to the file in the "(A Document Being Saved By myapplication)" 
folder, and it would have completed successfully.

Therefore NSPersistentDocument knows it's a "Save As" operation, but the 
persistent store thinks it's a "Save" operation to the originally opened file 
which it remembers internally.

I tried setting the persistent store's URL to nil, but that didn't work either, 
because it still tried to save it, only this time it was trying to save it to a 
nil file URL. It must still somehow know that it was loaded from a file.

I'm sure someone else must have come across this issue before. I'm sure there 
must be something simple I'm missing here, so would be glad of any 
suggestions...

Gideon
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to