Document-based SwiftData apps fail to identify a store on iPad?

When trying to run my document-based iPad app using iPadOS 18 beta and Xcode 16 beta, I get an error like the following after opening a document:

Thread 1: Fatal error: Failed to identify a store that can hold instances of SwiftData._KKMDBackingData<MyProject.MyModel> from [:]

In order to help track down what is going wrong, I downloaded the sample app from WWDC23 session "Build an app with SwiftData" found here: https://developer.apple.com/documentation/swiftui/building-a-document-based-app-using-swiftdata

When I try to run the end-state of that sample code, I get a similar error when running the app on my iPad and creating a new deck:

Thread 1: Fatal error: Failed to identify a store that can hold instances of SwiftData._KKMDBackingData<SwiftDataFlashCardSample.Card> from [:]

Given that the sample project is generating the same error as my own project, is this a problem with SwiftData and document-based apps in general? Or is there a change of approach that I should try?

Traditionally, UI/NSDocument-based architecture handles autosave pretty well, and I don't think DocumentGroup + SwiftData should be an exception in this regard.

As of today though, it seems that there is a bug related to SwiftData autosave, as discussed in the Xcode 16 MacOS Sequoia SwiftData not saving data after running application post.

Though you can probably work around the issue by explicitly saving the model context after making a change, I’d suggest that you file a feedback report against that autosave doesn't work in DocumentGroup + SwiftData – If you do so, please share your report ID here for folks to track.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Document-based SwiftData apps fail to identify a store on iPad?
 
 
Q