ios - Can't save Core Data -


i tried saving core data in tableview nsfetchedresultscontroller , different sections.

when add data following error appears:

coredata: error: serious application error. exception caught during core data change processing. bug within observer of nsmanagedobjectcontextobjectsdidchangenotification. * -[__nsplaceholderdictionary initwithobjects:forkeys:count:]: attempt insert nil object objects[0] userinfo (null) terminating app due uncaught exception 'nsinvalidargumentexception', reason: ' -[__nsplaceholderdictionary initwithobjects:forkeys:count:]: attempt insert nil object objects[0] *

first throw call stack: (0x181a05900 0x181073f80 0x1818f41a8 0x1818f4040 0x1000a9068 0x1000aa8d8 0x1835905a8 0x183505080 0x183504f48 0x183495108 0x1819aafc4 0x1819aa7e4 0x1819aa564 0x181a0fde4 0x1818eb0f4 0x1822dad2c 0x18349506c 0x1835098d0 0x18349378c 0x183492240 0x1000aa3a0 0x18672fe50 0x1868b34a4 0x18672fe50 0x18672fdcc 0x186717a88 0x186717bd4 0x18672f6e4 0x18672f314 0x186727e30 0x1866f84cc 0x1866f6794 0x1819bcefc 0x1819bc990 0x1819ba690 0x1818e9680 0x182df8088 0x186760d90 0x10004c23c 0x18148a8b8) libc++abi.dylib: terminating uncaught exception of type nsexception`

my code:

mydetaildata* mydetail = [nsentitydescription insertnewobjectforentityforname:@"mydetaildata" inmanagedobjectcontext:self._privateobjectcontext]; [mydetail setkategorie: nslocalizedstring(@"test", nil)]; nserror *error = nil; if (![mydetail.managedobjectcontext save:&error]) {       nslog(@"unresolved error %@, %@", error, [error userinfo]); } 

under ios6 fine code

here nsfetchedresultscontroller

- (nsfetchedresultscontroller *)fetchedresultscontroller2 {      if (fetchedresultscontroller2 != nil) {        return fetchedresultscontroller2;     }      nsfetchrequest *request = [[nsfetchrequest alloc] init];     nsentitydescription *entity = [nsentitydescription     entityforname:@"mydetaildata" inmanagedobjectcontext:_privateobjectcontext];     [request setentity:entity];      nssortdescriptor *kategoriedescriptor = [[nssortdescriptor alloc] initwithkey:@"kategorie" ascending:yes];     nssortdescriptor *oderdescriptor = [[nssortdescriptor alloc] initwithkey:@"order" ascending:yes];     nssortdescriptor *namedescriptor = [[nssortdescriptor alloc] initwithkey:@"name" ascending:yes];      nsarray *sortdescriptors = [[nsarray alloc] initwithobjects:kategoriedescriptor,oderdescriptor,namedescriptor, nil];     [request setsortdescriptors:sortdescriptors];       nsfetchedresultscontroller *afetchedresultscontroller = [[nsfetchedresultscontroller alloc] initwithfetchrequest:request managedobjectcontext:_privateobjectcontext sectionnamekeypath:@"kategorie" cachename:nil];     afetchedresultscontroller.delegate = self;     self.fetchedresultscontroller2 = afetchedresultscontroller;      return fetchedresultscontroller2;  }   

tableview delegates

  • numberofsectionsintableview
  • numberofrowsinsection
  • nsfetchedresultscontroller didchangeobject -> nsfetchedresultschangeinsert
  • nsfetchedresultscontroller didchangesection -> nsfetchedresultschangeinsert

called , contain right information - here relevant code:

- (nsinteger)numberofsectionsintableview:(uitableview *)tableview {     return [[fetchedresultscontroller2 sections] count]; }   - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section {     id <nsfetchedresultssectioninfo> sectioninfo = [[fetchedresultscontroller2 sections] objectatindex:section];     return [sectioninfo numberofobjects]; }   - (void)controller:(nsfetchedresultscontroller *)controller didchangeobject:(id)anobject atindexpath:(nsindexpath *)indexpath forchangetype:(nsfetchedresultschangetype)type newindexpath:(nsindexpath *)newindexpath {      if (userdrivendatamodelchange) return;      switch(type) {         case nsfetchedresultschangeinsert:             [self.tv insertrowsatindexpaths:[nsarray arraywithobject:newindexpath] withrowanimation:uitableviewrowanimationfade];             break;         case nsfetchedresultschangedelete:             [self.tv deleterowsatindexpaths:[nsarray arraywithobject:indexpath] withrowanimation:uitableviewrowanimationfade];             break;          case nsfetchedresultschangeupdate: {             [self configurecell:[self.tv cellforrowatindexpath:indexpath] atindexpath:indexpath];              nsstring *sectionkeypath = [controller sectionnamekeypath];             if (sectionkeypath == nil)                 break;              nsmanagedobject *changedobject = [controller objectatindexpath:indexpath];             nsarray *keyparts = [sectionkeypath componentsseparatedbystring:@"."];             id currentkeyvalue = [changedobject valueforkeypath:sectionkeypath];             (int = 0; < [keyparts count] - 1; i++) {                 nsstring *onepart = [keyparts objectatindex:i];                 changedobject = [changedobject valueforkey:onepart];             }             sectionkeypath = [keyparts lastobject];             nsdictionary *committedvalues = [changedobject committedvaluesforkeys:nil];              if ([[committedvalues valueforkeypath:sectionkeypath] isequal:currentkeyvalue])                 break;              nsuinteger tablesectioncount = [self.tv numberofsections];             nsuinteger frcsectioncount = [[controller sections] count];             if (tablesectioncount != frcsectioncount) {                 // need insert section                 nsarray *mysections = controller.sections;                 nsinteger newsectionlocation = -1;                 (id onesection in mysections) {                     nsstring *sectionname = [onesection name];                     if ([currentkeyvalue isequal:sectionname]) {                         newsectionlocation = [mysections indexofobject:onesection];                         break;                     }                 }                 if (newsectionlocation == -1)                     return; // uh oh                  if (!((newsectionlocation == 0) && (tablesectioncount == 1) && ([self.tv numberofrowsinsection:0] == 0)))                     [self.tv insertsections:[nsindexset indexsetwithindex:newsectionlocation] withrowanimation:uitableviewrowanimationfade];                 nsuinteger indices[2] = {newsectionlocation, 0};                 newindexpath = [[nsindexpath alloc] initwithindexes:indices length:2];             }           }          case nsfetchedresultschangemove:             [self.tv deleterowsatindexpaths:[nsarray arraywithobject:indexpath]                              withrowanimation:no];             [self.tv insertrowsatindexpaths:[nsarray arraywithobject:newindexpath]                              withrowanimation:no];             break;         default:             break;     } }   - (void)controller:(nsfetchedresultscontroller *)controller didchangesection:(id <nsfetchedresultssectioninfo>)sectioninfo atindex:(nsuinteger)sectionindex forchangetype:(nsfetchedresultschangetype)type {     switch(type) {          case nsfetchedresultschangeinsert:             if (!((sectionindex == 0) && ([self.tv numberofsections] == 1)))                 [self.tv insertsections:[nsindexset indexsetwithindex:sectionindex] withrowanimation:uitableviewrowanimationfade];             break;         case nsfetchedresultschangedelete:             if (!((sectionindex == 0) && ([self.tv numberofsections] == 1) ))                 [self.tv deletesections:[nsindexset indexsetwithindex:sectionindex] withrowanimation:uitableviewrowanimationfade];             break;         case nsfetchedresultschangemove:             break;         case nsfetchedresultschangeupdate:              break;         default:             break;     } } 

ideas whats going wrong?

problem solved. in

didchangeobject 

at

 case nsfetchedresultschangemove 

i changed line

 [self.tv deleterowsatindexpaths:[nsarray arraywithobject:indexpath]                          withrowanimation:no];    [self.tv insertrowsatindexpaths:[nsarray arraywithobject:newindexpath]                            withrowanimation:no]; 

to

   if (indexpath && newindexpath) {                  [self.tv deleterowsatindexpaths:[nsarray arraywithobject:indexpath]                          withrowanimation:no];                   [self.tv insertrowsatindexpaths:[nsarray arraywithobject:newindexpath]                            withrowanimation:no];   } else {                  nslog(@"a table item moved");   } 

Comments