In my NSDocument based app, my documents are to be associated with directories (they are an index of the directory)
I want to be able to open/save documents according to the following use case:
Opening a directory: a) if there is a .myapp file in the folder, open it b) else look if there is HASH-OF-PATH-basename.myapp file in ~/Library/Application Support/MyApp and open that b) else create a new document in memory
Opening an xxx.myapp file, as normal
Save / Autosave a) if source of current doc was 1b, 1c, or 2 save file to ~/Library/Application Support/MyApp/HASH-OF-PATH-basename.myapp b) if source of current doc was 1a, save to that .myapp file
Save As / Save To b) save an xxxxx.myapp to wherever the user specifies
The obvious thing seemed to be just to implement readFromURL:ofType:error:L and writeToURL:ofType:forSaveOperation:originalContentsURL:error: and switch URL as necessary based on what the saveoperation was.
This works in that I can open files and folders, and when I save an open folder my file is saved to Application Support, but then after writeToURL:ofType:forSaveOperation:originalContentsURL:error an error is raised and a dialog shown with the following error:
NSDocument could not delete the temporary item at
file://localhost/private/var/folders/6P/6PNpIB-6HreGE+Ikqf5dWU+++TI/
-Tmp-/TemporaryItems/(A%20Document%20Being%20Saved%20By%20MyApp%203)
/SomeDirectory.
Here's the error:
Error Domain=NSCocoaErrorDomain Code=4 UserInfo=0x200583a00
"“SomeDirectory” couldn’t be removed."