8

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?

Mark Krenek
  • 4,889
  • 3
  • 25
  • 17
  • 1
    I have some similar problems.. I don't see anything in the documentation related to this.l I don't see any delegate methods for showing documents or making some changes before a new document will be created. – Niels Jun 27 '20 at 11:12
  • 2
    Nope, stick with `UIDocumentBrowserViewController`. You can also present using the dedicated transition controller instead of pushing. DocumentGroup is a joke. – Procrastin8 Aug 14 '20 at 15:03
  • I am sticking with UIDocumentBrowserViewController for now. The other reason to do so is to handle conflict resolution. DocumentGroup and FileDocument don’t provide any support for this, that I see. – Mark Krenek Aug 14 '20 at 17:47
  • I feel too at least beta 6 its a toy. – zrfrank Aug 27 '20 at 17:52
  • Still a toy. Funny, macOS SwiftUI for once works better... – Ryan Apr 06 '21 at 18:54

0 Answers0