我有这个数组:
[[Lots: 2783, Development: Suntec City], [Lots: 1583, Development: Marina Square], [Lots: 594, Development: The Esplanade], [Lots: 1270, Development: Millenia Singapore], [Lots: 283, Development: Singapore Flyer], [Lots: 185, Development: Orchard Point], [Lots: 152, Development: The Heeren], [Lots: 595, Development: Plaza Singapura], [Lots: 77, Development: The Cathay], [Lots: 302, Development: Mandarin Hotel], [Lots: 1092, Development: Ngee Ann City], [Lots: 331, Development: Wisma Atria], [Lots: 1251, Development: VivoCity P3], [Lots: 933, Development: Sentosa], [Lots: 369, Development: Tang Plaza], [Lots: 932, Development: Harbourfront Centre], [Lots: 196, Development: Far East Plaza], [Lots: 324, Development: Centrepoint], [Lots: 218, Development: Concorde Hotel], [Lots: 434, Development: ION Orchard], [Lots: 194, Development: 313@Somerset], [Lots: 1971, Development: Resorts World Sentosa], [Lots: 726, Development: VivoCity P2], [Lots: 268, Development: Orchard Central], [Lots: 386, Development: Park Mall], [Lots: 812, Development: Marina Bay Sands]]
我想按字母顺序按“开发”值排序。我尝试使用sort by似乎只适用于字典
答案 0 :(得分:0)
这可以帮到你:
array.sort({ $0.Development > $1.Development })
请参阅this。
这是一个闭包的简称,它将第一个参数与第二个参数进行比较。 (假设两者都是字符串。)(你can compare strings using >
。)
答案 1 :(得分:0)
DataArray.sort {
item1, item2 in
let development1 = item1["Development"]! as String
let development2 = item2["Development"]! as String
return development1 > development2
}