SwiftData/ModelContext.swift:3253: Fatal error: Failed to identify a store that can hold instances of SwiftData._KKMDBackingData<Presents_2024.Item> from [:]

I'm still getting this error (SwiftData/ModelContext.swift:3253: Fatal error: Failed to identify a store that can hold instances of SwiftData._KKMDBackingData<Presents_2024.Item> from [:]) in Xcode 16.1 Beta (16B5001e).

The app works for a limited amount of time and then crashes with this error. It looks like the SwiftData model isn't being created properly and when a context is saved it crashes.

Can you tell me if this error will be fixed in the next beta?

Here's the output of the debug error when it crashes:

I'm also receiving the following failed assertion:

wiftData/ModelContext.swift:3253: Fatal error: Failed to identify a store that can hold instances of SwiftData._KKMDBackingData<Presents_2024.Item> from [:]
error: Assertion failed: (byte_size > 0 && byte_size <= 8 && "GetMaxU64 invalid byte_size!"), function GetMaxU64, file DataExtractor.cpp, line 527
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  LLDB                    0x0000000115319aac llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  LLDB                    0x0000000114e7a198 lldb_private::lldb_assert(bool, char const*, char const*, char const*, unsigned int) + 148
2  LLDB                    0x0000000114e73818 lldb_private::DataExtractor::GetMaxU64(unsigned long long*, unsigned long) const + 72
3  LLDB                    0x0000000114d7ded0 lldb_private::CompilerType::GetValueAsScalar(lldb_private::DataExtractor const&, unsigned long long, unsigned long, lldb_private::Scalar&, lldb_private::ExecutionContextScope*) const + 304
4  LLDB                    0x0000000114cb9b9c lldb_private::Value::ResolveValue(lldb_private::ExecutionContext*, lldb_private::Module*) + 388
5  LLDB                    0x0000000114cbc93c lldb_private::ValueObject::ResolveValue(lldb_private::Scalar&) + 104
6  LLDB                    0x0000000114cbf814 lldb_private::ValueObject::GetValueAsSigned(long long, bool*) + 140
7  LLDB                    0x0000000114b4fba8 lldb::SBValue::GetValueAsSigned(long long) + 160
8  lldb-rpc-server         0x0000000100c5fe70 rpc_server::_ZN4lldb7SBValue16GetValueAsSignedEx::HandleRPCCall(rpc_common::Connection&, rpc_common::RPCStream&, rpc_common::RPCStream&) + 92
9  lldb-rpc-server         0x0000000100c6a2b8 rpc_common::Connection::PrivateHandleRPCPacket(rpc_common::RPCPacket&, rpc_common::RPCPacket&, bool&) + 628
10 lldb-rpc-server         0x0000000100c6de8c Packets::ProcessPackets() + 564
11 lldb-rpc-server         0x0000000100c6dbf4 Packets::ReadThread() + 276
12 lldb-rpc-server         0x0000000100c6dad4 Packets::RunReadThread(void*) + 12
13 libsystem_pthread.dylib 0x00000001904f72e4 _pthread_start + 136
14 libsystem_pthread.dylib 0x00000001904f20fc thread_start + 8
Please file a bug report against lldb reporting this failure log, and as many details as possibleerror: Assertion failed: (byte_size > 0 && byte_size <= 8 && "GetMaxU64 invalid byte_size!"), function GetMaxU64, file DataExtractor.cpp, line 527
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  LLDB                    0x0000000115319aac llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  LLDB                    0x0000000114e7a198 lldb_private::lldb_assert(bool, char const*, char const*, char const*, unsigned int) + 148
2  LLDB                    0x0000000114e73818 lldb_private::DataExtractor::GetMaxU64(unsigned long long*, unsigned long) const + 72
3  LLDB                    0x0000000114d7ded0 lldb_private::CompilerType::GetValueAsScalar(lldb_private::DataExtractor const&, unsigned long long, unsigned long, lldb_private::Scalar&, lldb_private::ExecutionContextScope*) const + 304
4  LLDB                    0x0000000114cb9b9c lldb_private::Value::ResolveValue(lldb_private::ExecutionContext*, lldb_private::Module*) + 388
5  LLDB                    0x0000000114cbc93c lldb_private::ValueObject::ResolveValue(lldb_private::Scalar&) + 104
6  LLDB                    0x0000000114cbf6ec lldb_private::ValueObject::GetValueAsUnsigned(unsigned long long, bool*) + 140
7  LLDB                    0x0000000114b4fcc0 lldb::SBValue::GetValueAsUnsigned(unsigned long long) + 160
8  lldb-rpc-server         0x0000000100c5ff18 rpc_server::_ZN4lldb7SBValue18GetValueAsUnsignedEy::HandleRPCCall(rpc_common::Connection&, rpc_common::RPCStream&, rpc_common::RPCStream&) + 92
9  lldb-rpc-server         0x0000000100c6a2b8 rpc_common::Connection::PrivateHandleRPCPacket(rpc_common::RPCPacket&, rpc_common::RPCPacket&, bool&) + 628
10 lldb-rpc-server         0x0000000100c6de8c Packets::ProcessPackets() + 564
11 lldb-rpc-server         0x0000000100c6dbf4 Packets::ReadThread() + 276
12 lldb-rpc-server         0x0000000100c6dad4 Packets::RunReadThread(void*) + 12
13 libsystem_pthread.dylib 0x00000001904f72e4 _pthread_start + 136
14 libsystem_pthread.dylib 0x00000001904f20fc thread_start + 8
Please file a bug report against lldb reporting this failure log, and as many details as possible

Also getting these errors that might be related... 🤔

SwiftData/DefaultStore.swift:442: Fatal error: API Contract Violation: Editors must register their identifiers before invoking operations on this store SwiftData.DefaultStore: 68B5BA57-CC77-4EB2-AF60-60EE36D4B962 did not.
error: the replacement path doesn't exist: "/var/folders/6z/x5z1g5jx7bz8sd27794j7bpw0000gn/T/swift-generated-sources/@__swiftmacro_13Presents_20248ItemListV5items33_26959148E02528011C522F13E1D6E443LL5QueryfMa_.swift"
error: the replacement path doesn't exist: "/var/folders/6z/x5z1g5jx7bz8sd27794j7bpw0000gn/T/swift-generated-sources/@__swiftmacro_13Presents_20248ItemListV5items33_26959148E02528011C522F13E1D6E443LL5QueryfMa_.swift"

Can't show file for stack frame : <DBGLLDBStackFrame: 0x16bdfce20> - stackNumber:15 - name:ItemList.items.getter. The file path does not exist on the file system: /var/folders/6z/x5z1g5jx7bz8sd27794j7bpw0000gn/T/swift-generated-sources/@__swiftmacro_13Presents_20248ItemListV5items33_26959148E02528011C522F13E1D6E443LL5QueryfMa_.swiftCan't show file for stack frame : <DBGLLDBStackFrame: 0x16bdfce20> - stackNumber:15 - name:ItemList.items.getter. The file path does not exist on the file system: /var/folders/6z/x5z1g5jx7bz8sd27794j7bpw0000gn/T/swift-generated-sources/@__swiftmacro_13Presents_20248ItemListV5items33_26959148E02528011C522F13E1D6E443LL5QueryfMa_.swift

Here's how I initialize the SwiftData store using DocumentGroup. Please let me know if I need to provide any future info. Bug logged as Feedback (FB15100795)

//
//  Presents_2024App.swift
//  Presents 2024
//
//  Created by Benjamin Lee on 07/06/2024.
//

import RichTextKit
import SwiftData
import SwiftUI
import UniformTypeIdentifiers

@main
struct Presents_2024App: App {
    // MARK: Properties

    #if os(iOS)
        @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
    #elseif os(macOS)
        @NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
    #endif

    @Environment(\.modelContext) private var modelContext
    @FocusState private var isFocused: Bool

    @StateObject private var transientSettings = TransientSettings()

    // MARK: Computed Properties

    var body: some Scene {
        #if os(iOS)
            DocumentGroupLaunchScene("Present's 2024") {
                NewDocumentButton("New Activity...")
            } background: {
                Image(.background)
                    .resizable()
                    .scaledToFill()
                    .ignoresSafeArea()
            } overlayAccessoryView: { _ in
                AccessoryView()
            }
        #endif
        DocumentGroup(editing: .presentsDocument,
                      migrationPlan: Presents_2024MigrationPlan.self,
                      editor: {
                          RootView()
                              .environmentObject(appDelegate)
                              .environmentObject(transientSettings)
                              .focused($isFocused)
                              .onAppear {
                                  isFocused = true

                                  DispatchQueue.main.async {
                                      // Here, you might need to enforce the focus on the RootView
                                      #if os(macOS)
                                      if let window = NSApplication.shared.windows.first {
                                          window.makeFirstResponder(window.contentView)
                                      }
                                      #endif
                                  }
                              }
                              .onKeyPress(.leftArrow) {
                                  DispatchQueue.main.async {
                                      if transientSettings.selectedTab > 0 {
                                          transientSettings.selectedTab -= 1
                                      }
                                      print("⬅️ pressed")
                                  }
                                  return .handled
                              }
                              .onKeyPress(.rightArrow) {
                                  DispatchQueue.main.async {
                                      if transientSettings.selectedTab < transientSettings.numberOfItems - 1 {
                                          transientSettings.selectedTab += 1
                                      }
                                      print("➡️ pressed")
                                  }
                                  return .handled
                              }
                      },
                      prepareDocument: { context in
                          // Prepare the document before it is opened or edited.

                          // Insert example Bookend Item
                          let newBookend = Bookend(firstLine: NSAttributedString(""), secondLine: NSAttributedString(""), thirdLine: NSAttributedString(""), bookendType: .welcome)
                          let newItem = Item(itemText: "A Bookend Video", itemType: .bookend, order: 0)
                          newItem.bookends.append(newBookend)
                          context.insert(newItem)

                          // Insert example Question Item
                          let question = Question(questionText: NSAttributedString("An Example Question"))
                          let item = Item(itemText: "An Example Question", itemType: .question, order: 1)
                          item.questions.append(question)
                          context.insert(item)
                          context.insert(Brand.defaultBrand)
                      })
//        .commands {
//            SidebarCommands()
//            #if os(macOS)
        ////            AboutCommand()
//            #endif
//            RichTextCommand.FormatMenu()
//
        ////            CommandMenu("RichTextKit") {
        ////                DemoUrl.github.link
        ////                DemoUrl.documentation.link
        ////            }
//        }
    }
}

extension UTType {
    static var presentsDocument: UTType {
        UTType(exportedAs: "eu.makeitso.presentsdocument")
    }
}

struct Presents_2024MigrationPlan: SchemaMigrationPlan {
    static var schemas: [VersionedSchema.Type] = [Presents_2024VersionedSchema.self]

    static var stages: [MigrationStage] = []
}

struct Presents_2024VersionedSchema: VersionedSchema {
    static var versionIdentifier = Schema.Version(1, 0, 0)

    static var models: [any PersistentModel.Type] = [Item.self, UserSettings.self, Brand.self]
}

#Preview(traits: .sampleData) {
    @Previewable @State var appDelete = AppDelegate()
    @Previewable @State var transientSettings = TransientSettings()
    RootView()
        .environmentObject(appDelete)
        .environmentObject(transientSettings)
}

Have you made any progress on this? I too am seeing these errors after updating to Xcode 16, IOS 18, and macOS 15.0

I have the same issue. Has anyone found a workaround?

I have had some success by implementing manual saves using modelContext.transaction() whenever interacting with the model.

I'm having the same issue: random crashes after a few minutes of the app running, and a "Failed to identify a store that can hold instances of SwiftData" error.

I get the same error only while debugging. When I run on device it runs for a while then crashes.

I got the same error, too.

SwiftData/ModelContext.swift:3253: Fatal error: Failed to identify a store that can hold instances of SwiftData._KKMDBackingData&lt;Presents_2024.Item&gt; from [:]
 
 
Q