Swift sorting array of structs by string double

后端 未结 2 574
名媛妹妹
名媛妹妹 2021-01-27 01:56

I have an array of structs that I am looking to sort from highest to lowest based on Double value stored as a String. This is the way I\'m currently doing it:

us         


        
2条回答
  •  北荒
    北荒 (楼主)
    2021-01-27 02:24

    Use a comparator which is able to handle numeric strings

    users.sort { $0.weekFTC.compare($1.weekFTC, options: .numeric) == .orderedDescending }
    

提交回复
热议问题