MacCatalyst and the User's Documents Folder

I have a SwiftUI-based universal app which creates a file that it stores in documentsDirectory. On iOS/iPadOS, this file is stored in the application's Documents directory and is accessible via the Files app.

On MacCatalyst, this operation does the same thing — it creates the file and stores it in ~/Library/Containers/<app directory>/Data/Documents. However what I want is for the document to be stored in ~/Documents, so that it is easily accessible to the user.

How can I do that? I'd like it to occur without (for example) having to show a SaveFile panel...

Answered by galad87 in 870587022

Is your app sandboxed? If so, the only way is to show a NSOpenPanel and ask the user to select the Documents folder (or any other folder).

Showing an open panel and asking the user where to put the files is the best option even if the app is not sandboxed. Please don't litter the Documents folder with random things by default.

Accepted Answer

Is your app sandboxed? If so, the only way is to show a NSOpenPanel and ask the user to select the Documents folder (or any other folder).

Showing an open panel and asking the user where to put the files is the best option even if the app is not sandboxed. Please don't litter the Documents folder with random things by default.

Thank you. I get it.

I implemented a call to .fileExporter in the MacCatalyst case and it is an acceptable solution — only one extra mouse click.

However, I would like to point out that I'm not "littering the Documents folder with random things by default". In this case, the user chooses a "Save to File" option, which causes a carefully curated folder of information to be zipped and placed in their Documents folder for the purpose of being accessible for sharing with others - for example, so they can place it in Google Docs or Dropbox. (I also implement a "Send as an email attachment" option...) ...just sayin'

The destination folder should be configurable, not hard-coded to the Documents folder.

MacCatalyst and the User's Documents Folder
 
 
Q