dialogsave-asmac-catalyst

Mac Catalyst - standard dialog for save file


I want to implement standard Save As dialog in mac catalyst app. It should behave as in TextEdit - open a dialog, let user choose location and file format, and create file after clicking Save.

I have found UIDocumentPickerViewController , but I don't know:

  1. How to let user choose file format from the list of formats I offer
  2. How to initialize UIDocumentPickerViewController for export without already existing file. (I want to create file only after I know file format and location). I know about this contructor: init(urls: [URL], in: UIDocumentPickerMode) , which seems promising, but is deprecated.

Solution

  • You’re on the right lines with UIDocumentPickerViewController, but you must provide a URL and use UIDocumentPickerViewController(forExporting urls: [URL]).

    To get the URL, write the file data to the temporary directory, then pass the temporary URL as the argument.