Sort Array of Dictionaries by Key Value

后端 未结 5 1561
星月不相逢
星月不相逢 2020-11-30 15:18

I have an array of dictionaries and I want to sort them alphabetically by the \"itemName\" key in each dictionary. How can I do this in Swift?

I want to sort the ite

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-30 16:22

    This worked for me:

    let descriptor: NSSortDescriptor = NSSortDescriptor(key: "itemName", ascending: true)
    let sortedResults: NSArray = favArray.sortedArray(using: [descriptor]) as NSArray
    

提交回复
热议问题