Stevik
Stevik

Reputation: 1152

Swift error when added new entity (Core Data)

I have just created a new xcode project (Master-datail application) with Core Data. After I created a new entity (no code added into controllers) I have tried to open the app on iOS simulator and I got this error

2015-03-27 17:59:20.882 Blog Reader[2677:301117] CoreData: error: -addPersistentStoreWithType:SQLite configuration:(null) URL:file:///Users/stevik/Library/Developer/CoreSimulator/Devices/29A6C356-8AFA-48BA-B0C0-B6031D760ECE/data/Containers/Data/Application/88603D30-BAED-4F1A-95AB-ADD87C3A469B/Documents/Blog_Reader.sqlite options:(null) ... returned error Error Domain=NSCocoaErrorDomain Code=134100 "The operation couldn’t be completed. (Cocoa error 134100.)" UserInfo=0x78f4edd0 {metadata={ NSPersistenceFrameworkVersion = 519; NSStoreModelVersionHashes = { Event = <5431c046 d30e7f32 c2cc8099 58add1e7 579ad104 a3aa8fc4 846e97d7 af01cc79>; }; NSStoreModelVersionHashesVersion = 3; NSStoreModelVersionIdentifiers = ( "" ); NSStoreType = SQLite; NSStoreUUID = "25DE15EE-E903-4544-888B-7326455CF4B3"; "_NSAutoVacuumLevel" = 2; }, reason=The model used to open the store is incompatible with the one used to create the store} with userInfo dictionary { metadata = { NSPersistenceFrameworkVersion = 519; NSStoreModelVersionHashes = { Event = <5431c046 d30e7f32 c2cc8099 58add1e7 579ad104 a3aa8fc4 846e97d7 af01cc79>; }; NSStoreModelVersionHashesVersion = 3; NSStoreModelVersionIdentifiers = ( "" ); NSStoreType = SQLite; NSStoreUUID = "25DE15EE-E903-4544-888B-7326455CF4B3"; "_NSAutoVacuumLevel" = 2; }; reason = "The model used to open the store is incompatible with the one used to create the store"; } 2015-03-27 17:59:20.885 Blog Reader[2677:301117] Unresolved error Optional(Error Domain=YOUR_ERROR_DOMAIN Code=9999 "Failed to initialize the application's saved data" UserInfo=0x78ea27b0 {NSLocalizedDescription=Failed to initialize the application's saved data, NSUnderlyingError=0x78f4edf0 "The operation couldn’t be completed. (Cocoa error 134100.)", NSLocalizedFailureReason=There was an error creating or loading the application's saved data.}), Optional([NSLocalizedDescription: Failed to initialize the application's saved data, NSUnderlyingError: Error Domain=NSCocoaErrorDomain Code=134100 "The operation couldn’t be completed. (Cocoa error 134100.)" UserInfo=0x78f4edd0 {metadata={ NSPersistenceFrameworkVersion = 519; NSStoreModelVersionHashes = { Event = <5431c046 d30e7f32 c2cc8099 58add1e7 579ad104 a3aa8fc4 846e97d7 af01cc79>; }; NSStoreModelVersionHashesVersion = 3; NSStoreModelVersionIdentifiers = ( "" ); NSStoreType = SQLite; NSStoreUUID = "25DE15EE-E903-4544-888B-7326455CF4B3"; "_NSAutoVacuumLevel" = 2; }, reason=The model used to open the store is incompatible with the one used to create the store}, NSLocalizedFailureReason: There was an error creating or loading the application's saved data.])

Upvotes: 2

Views: 4426

Answers (2)

Jassi
Jassi

Reputation: 557

Whenever there is a change in your core data model whether an entity added or any attribute is changed. Delete the application from the simulator and run it again. It won't crash now.

Upvotes: 1

Tom Harrington
Tom Harrington

Reputation: 70946

You can't change the Core Data model and continue to use the same persistent store file unless you implement model migration. Apple provides considerable documentation on this. However during app development you can usually just delete the app from the device/simulator and install a new copy. That deletes any existing data, but often that's OK while working on the model.

Upvotes: 7

Related Questions