objective c - Sort NSMutableArray by date and then by alphabetical order -
i have nsmutable array of objects. objects represent football (soccer) matches , have nsstring parameter called title (ed "arsenal v chelsea"), , nsdate parameter called actualdate.
i sorting array date @ moment using following code:
nsmutablearray* = [self getmatchlistfromurl:@"http://www.url.com"]; [a sortusingdescriptors:@[[nssortdescriptor sortdescriptorwithkey:@"actualdate" ascending:yes]]]; obviously there multiple games happen on same date. sort games happen on same date in alphabetical order. there simple way this?
the method sortusingdescriptors takes array of nssortdescriptor argument. can pass multiple sort descriptors method follow:
nssortdescriptor *sortalphabetical = [nssortdescriptor sortdescriptorwithkey:@"title" ascending:yes]; nssortdescriptor *sortbydate = [nssortdescriptor sortdescriptorwithkey:@"actualdate" ascending:yes]; nsarray *sortdescriptors = @[sortalphabetical, sortbydate]; //perform sorting [a sortusingdescriptors:sortdescriptors];
Comments
Post a Comment