ios - When updating store, I get following error: NSUnderlyingException = "Cannot update object that was never inserted." -


my core data objects following:

author (name) >> book(title) >> notes(text, dateofnote)

relation boksbyauthor >> notesonbook

+(void)persistbookstodisk:(nsmanagedobjectcontext *)workercontext                  subclass:(eecorestack*)eecorestack                   fromurl:(nsurl*)fileurl{ [workercontext performblock:^{         nsarray * array = [ap_textextract componentseperatedbybooksfromtxtfile:fileurl];         (nsstring *body in array) { note *note = (note *) [nsentitydescription insertnewobjectforentityforname:@"note" inmanagedobjectcontext:workercontext];  note.dateofnote = [ap_textextract dateofnotefromstring:body]; note.text = [ap_textextract notetextfromstring:body];   book *book = (book *) [nsentitydescription insertnewobjectforentityforname:@"book" inmanagedobjectcontext:workercontext];             book.title = [ap_textextract booknamefromstring:body]; [book addnotesinbook: note];   author *author = (author*)[nsentitydescription insertnewobjectforentityforname:@"author" inmanagedobjectcontext:workercontext];             author.name = [ap_textextract authornamefromstring:body]; [author addbooksbyauthor: book]; }];  [eecorestack savetemporaryworkercontext:workercontext]; } 

savetemporarycontext:

- (void)savetemporaryworkercontext:(nsmanagedobjectcontext *)context { [context performblock:^{     nserror *error;     [context save:&error];     if (error) {         nslog(@"error saving temporary worker moc %@:  %@:", [error localizeddescription], [error userinfo]);     }else {          [self savemaincontext];     }  }]; }  - (void)savemaincontext {     [self.maincontext performblock:^{         nserror *error = nil;         [self.maincontext save:&error];         if(error){             nslog(@"error saving main moc %@: %@:", [error localizeddescription], [error userinfo]);         }else {             [self savemastercontext];         }     }]; }  - (void)savemastercontext {      [self.mastercontext performblock:^{         nserror *error = nil;         [self.mastercontext save:&error];         if(error){             nslog(@"error saving master context %@; : %@", [error localizeddescription], [error userinfo]);         }     }];     [[nsnotificationcenter defaultcenter] postnotificationname:@"donesavingmastercontext" object:nil];  } 

the data saved text file , saving follows pattern:

workercontext > maincontext > mastercontext (store)

first time data saved later when tries save updated text file (with change in note text), throws out following error:

error saving master context error occurred while saving.

; : {     nsaffectedobjectserrorkey =     (             "<note: 0x6000002d6570> (entity: note; id: 0x600001424480 <x-coredata:///note/t2371834c-1581-4a68-a56e-77e734b276cc1244> ; data:     text = \"quitely right );         nsunderlyingexception = "cannot update object never inserted.";     } 

one thing noticed after restarting app, data saved again start give same error after that.

edit 1: error show if, update existing attribute, not if insert new instance of attribute.

when updating data, first fetch core data object using nsfetchrequest , update necessary data. make attempt save. might trying update data without fetching.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -