objective c - iOS: [self.fetchedResultsController performFetch:&error]; makes my app to crash -


i have uitableviewcontroller, , want feed content of core data model. however, when fetch content app crashes. init method (i pass nsmanagedobjectcontext it).

- (id)initinmanagedobjectcontext:(nsmanagedobjectcontext *)context {     self = [super initwithstyle:uitableviewstyleplain];      if (self) {         nsfetchrequest *request = [[nsfetchrequest alloc] init];         request.entity = [nsentitydescription entityforname:@"document" inmanagedobjectcontext:context];         request.predicate = nil;             request.sortdescriptors = [nsarray arraywithobject:[nssortdescriptor sortdescriptorwithkey:@"iddoc"                                                                                       ascending:yes]];          /*          nserror *error = nil;          nsmanagedobject *retrieveddocument = [[context executefetchrequest:request error:&error] lastobject];          nslog(@"retrieveddocument %@", retrieveddocument);          */          nsfetchedresultscontroller *frc = [[nsfetchedresultscontroller alloc]                                              initwithfetchrequest:request                                               managedobjectcontext:context                                                 sectionnamekeypath:nil                                                          cachename:@"collectioncache"];          self.fetchedresultscontroller = frc;         [frc release];         [request release];           //here crashes         nserror *error;         [self.fetchedresultscontroller performfetch:&error];          if (error) {             // update handle error appropriately.             nslog(@"unresolved error %@, %@", error, [error userinfo]);             //exit(-1);  // fail         }      }     return self; } 

i'm sure context correctly passed because if uncomment commented snippet, stored data correctly printed.

my guess wrong fetchedresultscontroller.

thanks

the exception related wrong use of performfetch:

it returns bool tells success of fetch. if no allowed check nserror object. otherwise must not touch it.

probably methods use &error should used this:

    nserror *error;     if (![self.fetchedresultscontroller performfetch:&error]) {         // update handle error appropriately.         nslog(@"unresolved error %@, %@", error, [error userinfo]);         //exit(-1);  // fail     } 

Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -