Swift - Sort array of objects with multiple criteria

后端 未结 8 949
北荒
北荒 2020-11-22 11:19

I have an array of Contact objects:

var contacts:[Contact] = [Contact]()

Contact class:

Class Contact:NSOBjec         


        
8条回答
  •  有刺的猬
    2020-11-22 12:09

    How about:

    contacts.sort() { [$0.last, $0.first].lexicographicalCompare([$1.last, $1.first]) }
    

提交回复
热议问题