Sort Swift Array of Dictionaries by Value of a Key

前端 未结 5 1477
闹比i
闹比i 2021-02-07 05:45

I am attempting to sort a Swift array which is composed of dictionaries. I have prepared a working example below. The goal is to sort the entire array by the \"d\" element in t

5条回答
  •  北海茫月
    2021-02-07 06:09

    Sort Array of Dictionary in Swift 3 & 4

    let sortedResults = (userArray as NSArray).sortedArray(using: [NSSortDescriptor(key: "name", ascending: true)]) as! [[String:AnyObject]]
    

提交回复
热议问题