NSSortDescriptor in Swift

前端 未结 7 1645
长情又很酷
长情又很酷 2021-02-02 01:18

I am working on an iOS app and I have data stored in CoreData that I am loading into a UITableView. The data entities have an attribute called id which is a string

相关标签:
7条回答
  • 2021-02-02 02:00

    The Swifty way:

    var arr = ["A1", "A10", "A11", "A12", "A2", "A3"]
    arr.sort {dropFirst($0).toInt() < dropFirst($1).toInt()}
    

    So you could use that directly, or use it as the basis of the block for your comparator. If you insist on doing this in what is effectively Objective-C, you can use NSString compare:options: where the options: include NSNumericSearch.

    0 讨论(0)
提交回复
热议问题