Swift: Sort array of objects alphabetically

前端 未结 7 1059
梦如初夏
梦如初夏 2020-12-12 12:20

I have this:

class Movies {
  Name:String
  Date:Int
}

and an array of [Movies]. How do I sort the array alphabetically by name? I\'ve trie

7条回答
  •  生来不讨喜
    2020-12-12 12:56

    For those using Swift 3, the equivalent method for the accepted answer is:

    movieArr.sorted { $0.Name < $1.Name }
    

提交回复
热议问题