objective c - Retrieve Specific Object from Core Data -
i'm new core data
, wondering if possible object based on it's attributes, more specifically, uniqueid assigned it. i'm trying because i'm interfacing web server, provides data updated core data
. want search through each of web server objects, check timestamp, , if it's different, retrieve object core data, , update. i've looked @ using existingobjectwithid
seems have know object i'm searching for, or id of object. i've thought sorting data in both arrays, , checking each simultaneously, didn't think viable.
here i'm doing far:
-(nsmutablearray*) updaterootbeers:(nsmutablearray*)webrootbeerlist{ nsmanagedobjectcontext* moc = [self managedobjectcontext]; nsfetchrequest* fetchrequest = [[nsfetchrequest alloc]initwithentityname:@"rootbeer"]; coredatarootbeerlist = [[moc executefetchrequest:fetchrequest error:nil]mutablecopy]; //check see if core data has data, if not, call function populate list if (coredatarootbeerlist.count <=0) { [self addrootbeertocoredata:webrootbeerlist]; }else{ //otherwise want update core data object if object data different. for(rootbeer* currentrootbeer in webrootbeerlist){ rootbeer* mrootbeer = [moc existingobjectwithid:currentrootbeer error:nil]; } } }
i've thought using nested loops check data in each array, seems poor coding. or thoughts great.
you want make nsfetchrequest. can set entity , provide predicate. simple , clean.
Comments
Post a Comment