Let user pick document type to create when using SwiftUI & DocumentGroup

681 Views Asked by At

My document-based app supports several different file types. It is currently written in SwiftUI using a UIDocumentBrowserViewController. I'm trying to convert to the new SwiftUI (v2) DocumentGroup paradigm in which you don't directly use a UIDocumentBrowserViewController. I need to let the user pick which kind of document to create when they tap the Create button in the browser. Using DocumentGroup, I don't see how this is possible. When you create a DocumentGroup, you have to specify the document right there:

var body: some Scene {
    DocumentGroup(newDocument: TextDocument()) { file in
        TextDocumentEditor(document: file.$document)
    }
}

When using UIKit, the browser calls a delegate function didRequestDocumentCreationWithHandler that lets the app inject some UI for picking a document type, before proceeding on. In fact, what you can do is provide the document browser with a template file to be used for creating the new doc. Is that possible in SwiftUI 2?

0

There are 0 best solutions below