ios - Every time I add something to the CoreData file i get sigabrt -


every time add coredata (like adding attribute 1 of entities) sigabrt , thing helps deleting app emulator , cleaning project. added exception breakpoint , function breaks:

- (nspersistentstorecoordinator *)persistentstorecoordinator {     if (_persistentstorecoordinator == nil) {         nsurl *storeurl = [nsurl fileurlwithpath:[self datastorepath]];          _persistentstorecoordinator = [[nspersistentstorecoordinator alloc] initwithmanagedobjectmodel:self.managedobjectmodel];          nserror *error;         if (![_persistentstorecoordinator addpersistentstorewithtype:nssqlitestoretype configuration:nil url:storeurl options:nil error:&error]) {             nslog(@"error adding persistent store %@, %@", error, [error userinfo]);             abort();         }     }     return _persistentstorecoordinator; } 

if uncomment abort() app works wont access data, how can fix can add attribute without needing erase every time?

edit:added error.

2013-05-21 13:52:35.441 game[23595:c07] error adding persistent store error domain=nscocoaerrordomain code=134100 "the operation couldn’t completed. (cocoa error 134100.)" userinfo=0x7d6e5f0 {metadata={     nspersistenceframeworkversion = 419;     nsstoremodelversionhashes =     {         gametypeitem = <9b95d5f6 f27d2c7d 73452e34 c17e63a1 64bb657e 847085b3 12c5d3e0 17ea16b9>;         gametypelevelitem = <3224738f 99c7c8cf 4b23908a 356e345a 8b5d708a f68b7a2c f9de9ccb 0cec8fb8>;         sounditem = <eb8cc3cf 0d6b83b4 8c01bb5b 3d2dc6a2 3688577c 4d73e2f4 7742c00e 56fd78de>;     };     nsstoremodelversionhashesversion = 3;     nsstoremodelversionidentifiers =     (         ""     );     nsstoretype = sqlite;     nsstoreuuid = "f6fa6ed3-5663-4075-9d17-b38e4497468d";     "_nsautovacuumlevel" = 2; }, reason=the model used open store incompatible 1 used create store}, {     metadata =     {         nspersistenceframeworkversion = 419;         nsstoremodelversionhashes =         {             gametypeitem = <9b95d5f6 f27d2c7d 73452e34 c17e63a1 64bb657e 847085b3 12c5d3e0 17ea16b9>;             gametypelevelitem = <3224738f 99c7c8cf 4b23908a 356e345a 8b5d708a f68b7a2c f9de9ccb 0cec8fb8>;             sounditem = <eb8cc3cf 0d6b83b4 8c01bb5b 3d2dc6a2 3688577c 4d73e2f4 7742c00e 56fd78de>;         };         nsstoremodelversionhashesversion = 3;         nsstoremodelversionidentifiers =         (             ""         );         nsstoretype = sqlite;         nsstoreuuid = "f6fa6ed3-5663-4075-9d17-b38e4497468d";         "_nsautovacuumlevel" = 2;     };     reason = "the model used open store incompatible 1 used create store"; } 

edit:changed function this:

- (nspersistentstorecoordinator *)persistentstorecoordinator {     if (_persistentstorecoordinator == nil) {         nsurl *storeurl = [nsurl fileurlwithpath:[self datastorepath]];         _persistentstorecoordinator = [[nspersistentstorecoordinator alloc] initwithmanagedobjectmodel:self.managedobjectmodel];         nserror *error;          if (![_persistentstorecoordinator addpersistentstorewithtype:nssqlitestoretype configuration:nil url:storeurl options:@{nsmigratepersistentstoresautomaticallyoption:@yes, nsinfermappingmodelautomaticallyoption:@yes} error:&error])         {             [[nsfilemanager defaultmanager] removeitematurl:storeurl error:nil];             nslog(@"deleted old database %@, %@", error, [error userinfo]);             [_persistentstorecoordinator addpersistentstorewithtype:nssqlitestoretype configuration:nil url:storeurl options:@{nsmigratepersistentstoresautomaticallyoption:@yes} error:&error];             abort();         }     }     return _persistentstorecoordinator; } 

now runs program still doesnt show data

you need add nsmigratepersistentstoresautomaticallyoption & nsinfermappingmodelautomaticallyoption options:

try this:

if (![persistentstorecoordinator addpersistentstorewithtype:nssqlitestoretype configuration:nil url:storeurl options:@{nsmigratepersistentstoresautomaticallyoption:@yes, nsinfermappingmodelautomaticallyoption:@yes} error:&error]) {     [[nsfilemanager defaultmanager] removeitematurl:storeurl error:nil];     nslog(@"deleted old database %@, %@", error, [error userinfo]);     [persistentstorecoordinator addpersistentstorewithtype:nssqlitestoretype configuration:nil url:storeurl options:@{nsmigratepersistentstoresautomaticallyoption:@yes} error:&error]; } 

note: need turn on model versioning first , make sure create new version of data model each time change it.

read apple documentation model migration here.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -