ios - NSFetchedResultController Sction Name - Custom Sorting according to dates -
i using nsfetchedresultcontroller. below scenario want achieve.
i have table messages attributes messagedate(i.e. nsdate). need sort messages date labels today,yesterday,last week , older.
i tried using nssortdescriptor selector method selector method format returns nscomparisonresult object.
instead of sorting results, try add sort descriptors in fetch request itself. , create nsfetchedresultcontroller instance fetch request.
for example, use code snippet.
nssortdescriptor *sortdescriptor = [[nssortdescriptor alloc] initwithkey:@"messagedate" ascending:yes]; nsarray *sortdescriptors = [[nsarray alloc] initwithobjects:sortdescriptor, nil]; [fetchrequest setsortdescriptors:sortdescriptors]; nsfetchedresultscontroller *myfetchedresultscontroller = [[nsfetchedresultscontroller alloc] initwithfetchrequest:fetchrequest managedobjectcontext:managedobjectcontext sectionnamekeypath:@"message" cachename:nil];
Comments
Post a Comment