macOS SwiftUI document app always shows file picker on startup

DESCRIPTION OF PROBLEM When my Document-based macOS SwiftUI app starts up, it always presents a document picker. I would like it to open any documents that were open when the app last quit, and if none were open, open an "Untitled" document. I understand that there is a setting in System Settings-> Desktop & Dock ("Close windows when quitting an application") that will cause windows to reopen when it is turned off, but I'd like to give users a chance to opt-in for reopening docs even when that is turned on, since it is difficult to find, on by default, and might not be the desired behavior for all apps. I don't see any way to get a list of currently open documents to persist them at shutdown.

And even if that's considered a bad idea, I'd at least like a way to prevent the Document picker from being shown at startup and instead create an Untitled document if no documents were open.

Ideally, I'd like a way to provide this functionality in SwiftUI that doesn't require macOS 15 or later

STEPS TO REPRODUCE

Create a SwiftUI macOS document application in Xcode using the provided template, Give it any name you want

Run it, create a new ".exampletext" document, save it.

Quit the app with the document open. Re-run the app, document picker is shown.

Cancel the document picker and quit the app with no windows shown. Re-run the app, document picker is shown.

@navvadassity

You wrote:

I would like it to open any documents that were open when the app last quit, and if none were open, open an "Untitled" document. I don't see any way to get a list of currently open documents to persist them at shutdown, or a way to prevent the Document picker from being shown at startup and instead create an Untitled document if no documents were open.

State restoration isn't support in document based apps. Please file an enhancement request via Feedback Assistant and post the Feedback number here once you do.

You could use NSUserActivity to mimic state preservation, see Restoring Your App’s State

macOS SwiftUI document app always shows file picker on startup
 
 
Q