Sorting Array in Swift3

前端 未结 3 2002
遥遥无期
遥遥无期 2021-02-02 01:39

In my code, I have a struct like the following:

struct Object {
    var name: String
    var count: Int

I am now creating an array of 10 Object

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-02 02:21

    You can still use shorthand for sorted:

    objNameSorted = objArray.sorted { $0 < $1 }
    

    While less readable, it more closely mimics the sort syntax.

提交回复
热议问题