如何使用多个 属性 条件对自定义数组 class 进行排序?

How to sort array of custom class using more than one property criteria?

如何按多个属性对数组进行排序?

您要找的是KeyPathComparator。对集合进行排序时,您可以根据需要传递任意数量的属性:

let sorted = userItems.sorted(using: [.init(\.savedOn, order: .reverse), .init(\.title, order: .reverse))