How can I implement a template selection via creating a new document using DocumentGroup?

Hi.

I want to implement a template selection such as Pages and Numbers. Currently I am using DocumentGroup scene on SwiftUI.

How can I implement it?

init(
    newDocument: @autoclosure @escaping () -> Document,
    @ViewBuilder editor: @escaping (FileDocumentConfiguration<Document>) -> Content
)

The initializer of DocumentGroup may suggest that the newDocument argument should open template selector and return one when the selector is closed. But I think that it may beome a complicated implementation.

What is a right way to implement the template selector?

Replies

I solved it by myself.

newDocument argument returns a document with some magic keyword.

If a document of the argument of editor argument has the magic keyword, editor shows a template selector view.

The template selector view updates the document and it trigger showing a real editor view.