How do I sort an NSMutableArray with custom objects in it?

前端 未结 27 3364
予麋鹿
予麋鹿 2020-11-21 04:45

What I want to do seems pretty simple, but I can\'t find any answers on the web. I have an NSMutableArray of objects, and let\'s say they are \'Person\' objects

27条回答
  •  我寻月下人不归
    2020-11-21 05:06

    You have to create sortDescriptor and then you can sort the nsmutablearray by using sortDescriptor like below.

     let sortDescriptor = NSSortDescriptor(key: "birthDate", ascending: true, selector: #selector(NSString.compare(_:)))
     let array = NSMutableArray(array: self.aryExist.sortedArray(using: [sortDescriptor]))
     print(array)
    

提交回复
热议问题