Sorting NSString values as if NSInteger using NSSortDescriptor

前端 未结 7 1632
执念已碎
执念已碎 2020-11-28 09:10

I have created a sort descriptor to sort a plist response coming from my server. This works well with sort key having values upto 9. With more than 10 items I see abrupt res

7条回答
  •  日久生厌
    2020-11-28 09:44

    [list sortUsingSelector:@selector(localizedStandardCompare:)]; will sort the list in a "human" way (so "11" will come last, not between "1" and "2"). But if you really do want to treat these strings as numbers, you should make them number first!

提交回复
热议问题