CoreData: preview canvas won't work with 2x entities and relationship

I've tried to create a simple CoreData entity and use the PreviewProvider to display the results. This worked fine (The first entity that got displayed was the GoalInformation). After this i've extended my entity with a relationship to another entity. This is a screenshot from the Xcode editor:

More information about the entities:

This is my ContentView

struct ContentView: View {
    @Environment(\.managedObjectContext) private var viewContext
    
    @FetchRequest(
        sortDescriptors: [NSSortDescriptor(keyPath: \Goal.information!.name, ascending: true)],
        animation: .default)
    private var items: FetchedResults<Goal>
    
    var body: some View {
        VStack {
            Text("count: \(items.count)")
        }
        
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
            .environment(\.managedObjectContext, PersistenceController.preview.container.viewContext)
    }
}

The preview of the PersistenceController looks like this:

static var preview: PersistenceController = {
        let result = PersistenceController(inMemory: true)
        let viewContext = result.container.viewContext

        for _ in 0..<5 {
            let newItem = GoalInformation(context: viewContext)
            newItem.name = "Name"
            
            let newItem2 = Goal(context: viewContext)
            newItem2.information = newItem
        }
        do {
            try viewContext.save()
        } catch {
            let nsError = error as NSError
            debugPrint("\(nsError.code) + \(nsError.debugDescription)")
        }
        return result
    }()

The init of the same struct is this:

    init(inMemory: Bool = false) {
        container = NSPersistentCloudKitContainer(name: "goalz_two")
        if inMemory {
            container.persistentStoreDescriptions.first!.url = URL(fileURLWithPath: "/dev/null")
        }
        container.loadPersistentStores(completionHandler: { (storeDescription, error) in
            if let error = error as NSError? {
                debugPrint("\(error.code) + \(error.description)")
            }
        })
    }

When i want to display it by clicking "Resume" this is the error I receive.

Some more infos:

Error Domain=FBProcessExit Code=4 "The process crashed." UserInfo={NSLocalizedFailureReason=The process crashed., BSErrorCodeDescription=crash, NSUnderlyingError=0x600002e0fc00 {Error Domain=signal Code=4 "SIGILL(4)" UserInfo={NSLocalizedFailureReason=SIGILL(4)}}}

----------------------------------------

MessageSendFailure: Message send failure for relaunch

==================================

|  RemoteHumanReadableError: The operation couldn’t be completed. Transaction failed. Process failed to launch. (process launch failed)
|  
|  BSTransactionError (1):
|  ==error-reason: process launch failed
|  ==transaction: <FBApplicationProcessLaunchTransaction: 0x600001931340>
|  ==NSLocalizedFailureReason: Transaction failed. Process failed to launch. (process launch failed)
|  ==precipitating-error: Error Domain=FBProcessExit Code=4 "The process crashed." UserInfo={NSLocalizedFailureReason=The process crashed., BSErrorCodeDescription=crash, NSUnderlyingError=0x600002e0fc00 {Error Domain=signal Code=4 "SIGILL(4)" UserInfo={NSLocalizedFailureReason=SIGILL(4)}}}
|  ==error-description: Process failed to launch.

I'm so confused, because it worked when there was no relationship and i've only created one entity. Hope someone can help me out...

Using Xcode Version 13.2.1 on macOS 12.3

Answered by Developer Tools Engineer in 710028022

Hi,

Sorry to hear you are having problems getting previews working.

Crash logs for the preview app will show up in ~/Library/Logs/DiagnosticReports/. It can sometimes take a few minutes for it to generate, so give it a bit time and then see if any are there. Hopefully that will give you some helpful hints on what is causing the crash.

Based upon your description of the situation I am guessing that the preview version of the app has some stale app data (perhaps an old version of a CoreData container that doesn't have migration support to the current version?). To start from a fresh slate you can use the terminal app and run xcrun simctl --set previews delete all.

If that still doesn't resolve issue then probably best next step will be to file a feedback with diagnostics. We will need the diagnostics Xcode Previews generates in order to make sure we understand the error the previews system is encountering.

If you are having issues with macOS, catalyst or on-device iOS previews then download and install the logging profile for your device. Instructions and profiles are available here: https://developer.apple.com/bug-reporting/profiles-and-logs/?name=swift Attach the sysdiagnose to the radar as well as the diagnostics using the instructions below.

Then when you get an error in Xcode Previews, an error banner appears in the canvas

  1. Click the "Diagnostics" button in that banner
  2. In the sheet that appears, click "Generate Report" in the bottom left of the sheet
  3. Attach (or make from the folder) the resulting zip file to the bug (will be named something like previews-diagnostics-0123456789.zip)
Accepted Answer

Hi,

Sorry to hear you are having problems getting previews working.

Crash logs for the preview app will show up in ~/Library/Logs/DiagnosticReports/. It can sometimes take a few minutes for it to generate, so give it a bit time and then see if any are there. Hopefully that will give you some helpful hints on what is causing the crash.

Based upon your description of the situation I am guessing that the preview version of the app has some stale app data (perhaps an old version of a CoreData container that doesn't have migration support to the current version?). To start from a fresh slate you can use the terminal app and run xcrun simctl --set previews delete all.

If that still doesn't resolve issue then probably best next step will be to file a feedback with diagnostics. We will need the diagnostics Xcode Previews generates in order to make sure we understand the error the previews system is encountering.

If you are having issues with macOS, catalyst or on-device iOS previews then download and install the logging profile for your device. Instructions and profiles are available here: https://developer.apple.com/bug-reporting/profiles-and-logs/?name=swift Attach the sysdiagnose to the radar as well as the diagnostics using the instructions below.

Then when you get an error in Xcode Previews, an error banner appears in the canvas

  1. Click the "Diagnostics" button in that banner
  2. In the sheet that appears, click "Generate Report" in the bottom left of the sheet
  3. Attach (or make from the folder) the resulting zip file to the bug (will be named something like previews-diagnostics-0123456789.zip)
CoreData: preview canvas won't work with 2x entities and relationship
 
 
Q