ios - Sorting array in objective-c -
this question has answer here:
i trying sort dictionary's keys. trying using code shown above doing wrong.
self.tableinfodictionary = [responseobject objectforkey:@"division 4 herrar"]; self.rankssorted = [self.tableinfodictionary allkeys]; nslog(@"%@", self.rankssorted); self.rankssorted = [[self.tableinfodictionary allkeys] sortedarrayusingselector:@selector(localizedcaseinsensitivecompare:)]; nslog(@"-------------------------%@", self.rankssorted); the output looks this: why 10 not supposed be?
2015-04-24 19:06:24.884 gbglivescore[14574:418925] ( 10, 2, 3, 11, 4, 5, 6, 7, 0, 8, 1, 9 ) 2015-04-24 19:06:24.885 gbglivescore[14574:418925] -------------------------( 0, 1, 10, 11, 2, 3, 4, 5, 6, 7, 8, 9 )
they're strings, , they're in lexicographical order. string "10" comes before "2" because compares first characters, "1" , "2", , "1" comes before "2".
if want them sorted numbers, you'll first have convert them numbers, or you'll have write custom sort method , use instead.
Comments
Post a Comment