The array uses the System method compare to do the simple sorting of letters
nsarray *oldarray = @[@ "BAC", @ "Bzd", @ "AZC", @ "Azz"];
Nsarray *newarray = [Oldarray sortedarrayusingselector:@selector (compare:)];
NSLog(@ "New array =%@", NewArray);
Because Nsdictionary sort
Nsmutabledictionary *dict = [[Nsmutabledictionary alloc] init];
[Dict SetObject:@ "1" Forkey:@ "Key1"];
[Dict SetObject:@ "2" Forkey:@ "Key2"];
[Dict SetObject:@ "3" Forkey:@ "Key3"];
[Dict SetObject:@ "4" Forkey:@ "Key4"];
For (nsstring *str in [dict AllKeys]) {
NSLog (@ "key = =%@", str);
}
Nsarray *keys = [dict allKeys];
Nsarray *sortedarray = [keys sortedarrayusingcomparator:^nscomparisonresult (ID obj1, ID obj2) {
return [obj1 compare: Obj2 options: Nsnumericsearch];
}];
For (nsstring *categoryid in sortedarray) {
NSLog(@ "[dict objectforkey:categoryid] = = = =%@", [dict objectforkey: categoryId]);
}
iOS simple sort-alphabetical sort, nsdictionary sort