Hi everyone,
I'm building a Wiki editor/viewer document based app for one of my projects.
The Document file type is a bundle which contains this hierarchy:
Example.wikidoc:
- stylesheet.css
- metadata.json
- wiki/
[From here all the wiki articles I.e files and folders containing files]
When creating an "untitled" document, in the init() of my NSDocument subclass (Document) I create a temporary "wiki/" directory somewhere on the file system (The App is Sandboxed). I store the "wiki/" directory URL (var wikiRoot: URL) to be used in my view controller to interact with the wiki engine.
From there, the user starts editing/adding pages, they are saved in the wikiRoot directory.
So far so good... the user saves the document:
1) in my override of NSDocument.write(to url: URL, ofType: String)
I create a document file wrapper (documentFileWrapper) and add the regular contents for the stylesheet and the metadata and a directory filewrapper for the wiki directory (no content specified)
2) I then call: try documentFileWrapper.write(to: url, options: [], originalContentsURL: nil)
It saves the contents, with everything. The files and the wiki directory with everything in it. I can check this by showing the contents of the document bundle in the Finder.
BUT I should now be changing the wikiRoot URL to reflect the relocated saved document bundle.
Problem is the url provided in override func write(to url: URL, ofType typeName: String) throws Is not the real saved URL, maybe an intermediary URL while creating the bundle. For example on my system:
/var/folders/c9/fhk113dd19j0vh_kv6fpfsvw0000gn/T/com.montecarlo-computing.WikiEditor/TemporaryItems/(A Document Being Saved By WikiEditor 3)/test.wikidoc
And of course the document.fileURL is nil...
How am I supposed to get the real new "wiki/" URL of the saved document bundle?
Any advice would be really really appreciated!
Thanks and regards,
Thierry