objective c - NSSortDescriptor error : " [NSSortDescriptor count]: unrecognized selector sent to instance " -
i trying setup nsfetchedresultscontroller
fetch request , keep getting error:
"[nssortdescriptor count]: unrecognized selector sent instance"
below code. model has 1 record trying fetch. following paul heagarty's 2010-2011 core data demo video set core data.
nsfetchrequest *request = [nsfetchrequest fetchrequestwithentityname:@"temple"]; nssortdescriptor *sortdescriptor = [[nssortdescriptor alloc] initwithkey:@"name" ascending:no]; nsarray *sortdescriptors = [[nsarray alloc] initwithobjects:sortdescriptor, nil]; [request setsortdescriptors:sortdescriptors]; request.predicate = nil; self.fetchedresultscontroller = [[nsfetchedresultscontroller alloc] initwithfetchrequest:request managedobjectcontext:self.eventdatabase.managedobjectcontext sectionnamekeypath:nil cachename:nil];
// cause of error: assigning nssortdescriptor property expects nsarray fetchrequest.sortdescriptors = [nssortdescriptor sortdescriptorwithkey:@"name" ascending:yes]; // solution: wrap sort descriptor in array, fixes error fetchrequest.sortdescriptors = @[[nssortdescriptor sortdescriptorwithkey:@"name" ascending:yes]];
Comments
Post a Comment