SwiftUI ReferenceFileDocument and Document-scoped bookmarks

Context
I'm writing an app that allows a user to select folders, and then scan them for files. The folder could be on the user's machine, iCloud or external storage. The app persists the details of these files and folders to a document, so the user can access the files or re-scan the folders in the future. The App is being written using the SwiftUI framework for MacOS and the iPad.

Problems
Given this is a Sandboxed app I need to create security-scoped bookmarks to be able to access the files and folders that have been persisted to the document. I have two questions:
  1. How can I create a document-scoped bookmark, when using ReferenceFileDocument protocol. I need the document's URL, but I will never have access to this as I'm using the ReferenceFileDocument. I want to achieve something like this:

Code Block  
func fileWrapper(snapshot: MyDocument, configuration: WriteConfiguration) throws -> FileWrapper {
:
let bookmarkDataToPersist = snapshort.sourceFolderURL.bookmarkData(options: .withSecurityScope, includingResourceValuesForKeys: nil, relativeTo: documentURL)
:
}

2. Ideally the user would be able to:
* connect an external drive to their Mac
* select a folder on that drive
* save the document, which would persist a bookmark to that folder's URL
* send the document to an iPad (via email or iCloud drive)
* open the document using the iPad version of the App
* connect the external bookmark to the iPad
* re-scan the folder which was book marked in the document from the folder

But given the problem in 1) and the fact that document-bookmarks cannot point to folders, is there a way?

Any ideas or suggestions would be very welcome



SwiftUI ReferenceFileDocument and Document-scoped bookmarks
 
 
Q