Document-based app always opens untitled document even when a document is restored

If my NSDocument.canConcurrentlyReadDocuments(ofType:) implementation returns true, often when launching the app, an untitled document is created regardless whether another document is restored. If document reading is not concurrent, an untitled document is only created when no other document is restored, as expected.

The issue happens on most app launches when a document is restored. If the restored document takes long to load (which can be simulated by putting sleep(1) in the Document.read(from:ofType:) implementation), the issue always happens.

Is this expected, or is there a workaround?

I created FB25340015.

Answered by DTS Engineer in 917203022

Thanks for filing FB25340015 with a focused project and a screen recording. The recording shows the steps that reproduce it, including clicking Run again in Xcode. I checked on FB25340015, and it's open and under investigation.

I read through your project, and its code doesn't do anything unusual. On macOS 27.0.1 with Xcode 27.2, your project reproduces the extra untitled document for me, but only when Xcode launches the app. After I saved the document and clicked Run again, the restored document and a new untitled document both opened. When I launched the same build from the Finder, it reopened the documents that were open when it quit. It didn't add an untitled document. Turning off "Debug executable" or "Allow debugging when browsing versions" in the scheme's Run settings didn't change the Xcode result.

Does the extra document appear when you launch your app from the Finder on macOS 27.2? Either way, please add the result to FB25340015.

Please continue to test your software in release and pre-release versions of system software made available to you through your developer.apple.com account. When you do, add details about that into your bug report to keep it up to date. Please see developer.apple.com/download.

Thanks for filing FB25340015 with a focused project and a screen recording. The recording shows the steps that reproduce it, including clicking Run again in Xcode. I checked on FB25340015, and it's open and under investigation.

I read through your project, and its code doesn't do anything unusual. On macOS 27.0.1 with Xcode 27.2, your project reproduces the extra untitled document for me, but only when Xcode launches the app. After I saved the document and clicked Run again, the restored document and a new untitled document both opened. When I launched the same build from the Finder, it reopened the documents that were open when it quit. It didn't add an untitled document. Turning off "Debug executable" or "Allow debugging when browsing versions" in the scheme's Run settings didn't change the Xcode result.

Does the extra document appear when you launch your app from the Finder on macOS 27.2? Either way, please add the result to FB25340015.

Please continue to test your software in release and pre-release versions of system software made available to you through your developer.apple.com account. When you do, add details about that into your bug report to keep it up to date. Please see developer.apple.com/download.

Thanks. I can confirm that it only happens when running the app from Xcode, and I updated the feedback.

I am also experiencing this when running my app from Xcode.