NSSortDescriptor in Swift

前端 未结 7 1642
长情又很酷
长情又很酷 2021-02-02 01:18

I am working on an iOS app and I have data stored in CoreData that I am loading into a UITableView. The data entities have an attribute called id which is a string

7条回答
  •  情歌与酒
    2021-02-02 01:39

    for swift 4.2

    You can sort array using NSSortDescriptor

    let descriptor: NSSortDescriptor = NSSortDescriptor(key: "lastMessageDate", ascending: false)
    let sortedResults = arrChatDialogs?.sortedArray(using: [descriptor])
    

提交回复
热议问题