How to sort an array which contains Dictionaries?

前端 未结 5 404
Happy的楠姐
Happy的楠姐 2020-12-30 20:05

I have an array which contains dictionaries in it; so how can I sort the array according to dictionary key values?

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-30 20:48

     let arrDescriptor = NSSortDescriptor(key: "order", ascending: true)
     let sortDescriptors: NSArray = [arrDescriptor]
     let sortedArray = instancesubArray.sortedArray(using: sortDescriptors as [AnyObject] as [AnyObject] as! [NSSortDescriptor])
    
     print(sortedArray)
    

提交回复
热议问题