The elements in the array are dictionaries, one of the elements in the dictionary, such as name, now needs to be sorted by the first letter of the name.
The procedure is simple, add an element to the dictionary, save the first letter of the name, and then sort it in the following way.
-(void) Sortwifilist {
Nsarray *resultarray = [Mydataarray sortedarrayusingfunction:compare context:null];
[Mydataarray removeallobjects];
[Mydataarray Addobjectsfromarray:resultarray];
}
Nscomparisonresult Compare (Nsdictionary *firstdict, nsdictionary *seconddict, void *context) {
if ([[Firstdict objectforkey:@ "Ssidsortkey"] intvalue] < [[Seconddict objectforkey:@ "Ssidsortkey"] intValue])
return nsorderedascending;
else if ([[Firstdict objectforkey:@ "Ssidsortkey"] intvalue] > [[seconddict objectforkey:@ "Ssidsortkey"] intValue])
return nsordereddescending;
Else
return nsorderedsame;
}
iOS development-Sort by an element in the dictionary in the array