0

Code build but I get fatal error on launch while loading the Core data

lazy var persistentContainer: NSPersistentContainer = {
    /*
     The persistent container for the application. This implementation
     creates and returns a container, having loaded the store for the
     application to it. This property is optional since there are legitimate
     error conditions that could cause the creation of the store to fail.
    */
    let container = NSPersistentContainer(name: "GridModel")
    container.loadPersistentStores(completionHandler: { (storeDescription, error) in
        if let error = error as NSError? {

            fatalError("Unresolved error \(error), \(error.userInfo)")
        }
    })
    return container
  }()

The error message in the output window is:

myApp[8117:177239] [error] error: -addPersistentStoreWithType:SQLite configuration:(null) URL:file:///Users/xyz/Library/Developer/CoreSimulator/Devices/B58967C7-E8BA-4ED9-826A-1AB52B6C1EAC/data/Containers/Data/Application/94CFF817-B0C6-4BF4-8979-382E7C74485F/Library/Application%20Support/GridModel.sqlite options:{
    NSInferMappingModelAutomaticallyOption = 1;
    NSMigratePersistentStoresAutomaticallyOption = 1;
} ... returned error Error Domain=NSCocoaErrorDomain Code=134140 "(null)" UserInfo={sourceModel=(<NSManagedObjectModel: 0x60000028e740>) isEditable 1, entities {..... lists all the entities with long list of errors here.. }

I think I accidentally clicked on Xcode menu -> Editor -> Add Model Version.

Looks like some error in the Model. I am not sure if this caused the error and I dont understand how and why?'

Can someone please advise?

user1046037
  • 16,755
  • 12
  • 92
  • 138
vrao
  • 545
  • 2
  • 12
  • 33
  • I was trying to regenerate some NSMangedObject classes, after which I ran into this error. – vrao Jul 29 '18 at 22:58
  • Take a backup of your project then In Xcode in the file navigator on the left panel if you expand the xcdatamodel file you would see 2 models. See which one has a green tick that is the one used. Try and make the original as the one to use and delete the other model. Always use version control so that you can revert to a previous version – user1046037 Jul 30 '18 at 00:12
  • I checked my project there is only one xcdatamodelid. I dont know what could be wrong – vrao Aug 03 '18 at 03:34
  • Found the solution refer link: https://stackoverflow.com/questions/5517129/core-data-cocoa-error-134100 – vrao Aug 03 '18 at 04:14

0 Answers0