Sort Array of Dictionaries by Key Value

后端 未结 5 1559
星月不相逢
星月不相逢 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条回答
  •  攒了一身酷
    2020-11-30 15:55

    I have an array of dictionaries and i am sorting my array with alphabetically by the "firstname" key in each dictionary. You can also sort your array by just putting your array name in this code and your keyName

    /*

     let descriptor: NSSortDescriptor =  NSSortDescriptor(key: "firstname", ascending: true, selector: #selector(NSString.caseInsensitiveCompare(_:)))
     let sortedResults: NSArray = yourArrayName.sortedArrayUsingDescriptors([descriptor])
    
      self.user_Array = NSMutableArray(array: sortedResults)
    

    */

    Hopefully it helps you.

提交回复
热议问题