Core Data boilerplate project causes Fatal Error

I'm using Xcode 16 and SwiftUI targeting iOS 18. I'm new to Core Data, and when I create a new project and select to use Core Data as storage, I get boilerplate code for it.

The problem is that when I try to see the preview without any change to the code, I get a Fatal Error:

CrashReportError: Fatal Error in Persistence.swift
    
    Test crashed due to fatalError in Persistence.swift at line 52.
    
    Unresolved error Error Domain=NSSQLiteErrorDomain Code=8 "(null)" UserInfo={NSFilePath=/Users/monni/Library/Developer/Xcode/UserData/Previews/Simulator Devices/D0D98B5B-7E6F-4DC3-B16A-34D6D2958558/data/Containers/Data/Application/A98879A6-46F5-4E29-B2D7-AD294F1EFFD0/Library/Application Support/Test.sqlite, NSSQLiteErrorDomain=8}, ["NSSQLiteErrorDomain": 8, "NSFilePath": /Users/monni/Library/Developer/Xcode/UserData/Previews/Simulator Devices/D0D98B5B-7E6F-4DC3-B16A-34D6D2958558/data/Containers/Data/Application/A98879A6-46F5-4E29-B2D7-AD294F1EFFD0/Library/Application Support/Test.sqlite]

When I try to open the SQLite database there are no entities in it. I have also tried xcrun simctl --set previews delete all, but with no luck.

Hi @monni, I'm sorry to hear you're running into an issue with Previews in the CoreData template project

I just made a new project from that template and it seems to work alright for me. The fatalError you indicate implies that the container is failing to load the persistent store, which is surprising if you haven't made any changes to the code or the data model file.

Does it only fail in Previews (i.e., does it work if you choose Build and Run)? If you create a new template project using SwiftUI and CoreData with a project name you haven't used before (or update your bundle ID to something you haven't used before), make no changes, and attempt to view the ContentView preview, does it fail in this case as well?

Hi,

It runs normally with a simulator, so the problem is just with previews. I created a new project using a new name and different bundle ID and did not make any changes, but the preview crashed with the same fatalError.

Core Data boilerplate project causes Fatal Error
 
 
Q