I am developing a SwiftUI iOS app which originally started out with A WindowGroup. In another view, I have decided that I need to present that view as a DocumentGroup scene to take advantage of all the features that come with it. I don't want the entry point into the app to be a DocumentGroup scene. I would just like the entry point into my App to be a WindowGroup scene, then in another view from the WindowGroup Scene, I would like to call the DocumentGroup scene to open as if the app was a document-based app. Any help will be much appreciated. Thanks
Asked
Active
Viewed 618 times
5
-
Have you been able to figure this out or have you had to change your design? – Ferdinand Rios Aug 16 '21 at 20:13
-
@FerdinandRios I had to change my design since I didn't have enough time to dig deeper. I just used document picker in place of a DocumentGroup scene in the view where I wanted it and hacked my way around it. – Heyman Aug 18 '21 at 06:05
-
I do the same thing. Do you use a UIDocument or a FileDocument? I use a UIDocument but was trying to figure out how to use a FileDocument instead. – Ferdinand Rios Aug 18 '21 at 18:47
-
@FerdinandRios I use UIDocument because I never figured out how to use the FileDocument. Let me know when you figured it out. – Heyman Aug 18 '21 at 19:38
-
I wound up doing the same thing. – Ferdinand Rios Sep 16 '21 at 19:26
1 Answers
1
I tested in Xcode 13.3 and macOS 12.3 I noticed if WindowGroup
is declared first then only that window opens and the file browser doesn't when launching the app and if closing the window and then clicking on the app's dock icon it opens a new window again. Unfortunately I noticed a bug that if you command+quit the app (rather than stopping it) on next relaunch it shows both the window and the file browser instead of just the window (I'll report that).
import SwiftUI
@main
struct DocumentTestApp: App {
var body: some Scene {
WindowGroup("Hello") { // group order matters
VStack {
Text("Hello")
Button("New") {
NSDocumentController.shared.newDocument(nil)
}
}
.padding()
}
}
DocumentGroup(newDocument: DocumentTestDocument()) { file in
ContentView(document: file.$document)
}
DocumentGroup(newDocument: DocumentTestDocument2()) { file in
ContentView2(document: file.$document)
}
}
}

malhal
- 26,330
- 7
- 115
- 133
-
This doesn't answer the question as it is a question related to only iOS. – Heyman Aug 27 '22 at 09:01