Not Showing FileOpen with Document-

I have developed several document-based (NSDocument) applications for macOS is Cocoa. Now, I'm playing with a document app project in SwiftUI. If I launch the application out of box, a file-select panel will open just as you see in TextEdit. (Please see the picture below) How do we prevent it from appearing? I would rather show a blank window, which in fact appears if I just press Command + N. Thanks.

Answered by DTS Engineer in 836705022

You can use .defaultLaunchBehavior(.suppressed) to suppress the scene in the absence of any previously restored scenes. For example:

@main
struct WritingApp: App {
var body: some Scene {
DocumentGroup(newDocument: WritingAppDocument()) { file in
StoryView(document: file.$document)
}
.defaultLaunchBehavior(.suppressed)
}
}
Accepted Answer

You can use .defaultLaunchBehavior(.suppressed) to suppress the scene in the absence of any previously restored scenes. For example:

@main
struct WritingApp: App {
var body: some Scene {
DocumentGroup(newDocument: WritingAppDocument()) { file in
StoryView(document: file.$document)
}
.defaultLaunchBehavior(.suppressed)
}
}

Thanks a lot, DTS Engineer. I guess defaultLaunchBehavior(_:) is available for macOS 15.0 or higher. I guess I have to switch back to Cocoa with Storyboard since I also need to use TextSelection.

Not Showing FileOpen with Document-
 
 
Q