ios - Core Data Fetch Request for Deleting Records Returns No Results -


i have stand alone coredata entity contains approximately 30 records. periodically have delete records , repopulate associated coretableviewcontroller. nsfetchrequest not returning records.

but exact same fetchrequest in setupfetchedresultscontroller return records.

i sure missing obvious here, have not figured out what. ideas?

 - (void)erasefetchedresults:(nsmanagedobjectcontext *)mycontext  {  nsfetchrequest *allathletes = [nsfetchrequest fetchrequestwithentityname:@"resultsforathletesearch"]; allathletes.sortdescriptors = [nsarray arraywithobject:[                 nssortdescriptor sortdescriptorwithkey:@"orderrecordsdownloaded"                                              ascending:yes]]; // no predicate because want athletes  [allathletes setincludespropertyvalues:yes]; //only fetch managedobjectid  nserror * error = nil; nsarray * athletes = [mycontext executefetchrequest:allathletes error:&error]; nslog(@"nsarray athletes %d", [athletes count]); //error handling goes here (nsmanagedobject * athlete in athletes) {     [mycontext deleteobject:athlete]; } nserror *saveerror = nil; [mycontext save:&saveerror];  }    - (void)setupfetchedresultscontroller // attaches nsfetchrequest uitableviewcontroller  {  nsfetchrequest *request = [nsfetchrequest fetchrequestwithentityname:@"resultsforathletesearch"]; request.sortdescriptors = [nsarray arraywithobject:[nssortdescriptor sortdescriptorwithkey:@"orderrecordsdownloaded" ascending:yes]]; // no predicate because want athletes  self.fetchedresultscontroller = [[nsfetchedresultscontroller alloc]  initwithfetchrequest:request                                                                       managedobjectcontext:self.athletesearchdatabase.managedobjectcontext                                                                        sectionnamekeypath:nil                                                                                 cachename:nil]; } 

here calling method:

 - (void)usedocument  {  nslog(@"does athletesearchdatabase exist? %d", [[nsfilemanager defaultmanager] fileexistsatpath:[self.athletesearchdatabase.fileurl path]]); nsstring *checkname = _searchname; if (![[nsfilemanager defaultmanager] fileexistsatpath:[self.athletesearchdatabase.fileurl path]]) {     // not exist on disk, create     [self.athletesearchdatabase savetourl:self.athletesearchdatabase.fileurl forsaveoperation:uidocumentsaveforcreating completionhandler:^(bool success) {         [self setupfetchedresultscontroller];          nslog(@"checkname %@ before calling fetchathletesearchresultsintodocument.",checkname);           [self fetchathletesearchresultsintodocument:self.athletesearchdatabase wherenameis:checkname];     }]; } else if (self.athletesearchdatabase.documentstate == uidocumentstateclosed) {     // exists on disk, need open     [self erasefetchedresults:self.athletesearchdatabase.managedobjectcontext];     [self.athletesearchdatabase openwithcompletionhandler:^(bool success) {          [self setupfetchedresultscontroller];         [self fetchathletesearchresultsintodocument:self.athletesearchdatabase wherenameis:checkname];     }]; } else if (self.athletesearchdatabase.documentstate == uidocumentstatenormal) {     // open , ready use     [self setupfetchedresultscontroller]; } } 

well, did not figure out why particular fetch request return no records, employed matthew frederick's solution question asked here. able overwrite records , came away more elegant solution.

will post more details if interested.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -