np2314
np2314

Reputation: 685

SwiftUI preview crash after modify core data entity's attribute

Prior to this issue, the preview is running fine. However, after I have changed the type of the attribute (e.g. from String to Float) inside a .xcdatamodeld file and modify the manual definition file accordingly, which looks similar to this

public class test01: NSManagedObject, Identifiable {
    @NSManaged public var var01: String
    ...
}

The simulation crashes on first few tries but works again after I removed the application inside the simulation iPhone. But then when I tried to use the preview, it always show an error tab saying that it always crashed in updating the view, even the simplest starter file, "Hello World", given when creating the SwiftUI preview file.

Application Specific Information: Fatal error: Unresolved error Error Domain=NSCocoaErrorDomain Code=134140 "Persistent store migration failed, missing mapping model." UserInfo={destinationModel=() isEditable 0

At this point I could not find the solution, any idea on this bug/problem?

Upvotes: 12

Views: 2376

Answers (1)

Monica Granbois
Monica Granbois

Reputation: 7212

Try deleting the preview canvas simulators as well. They exist in:

~/Library/Developer/Xcode/UserData/Previews/Simulator Devices/

The preview canvas probably has the old version of the data model.

You may need to do this command at command line:

killall -9 com.apple.CoreSimulator.CoreSimulatorService

And restart XCode as well.

Upvotes: 38

Related Questions