'How to sort array of data from one class by criteria of String from another class?

How to compare two classes datas?



Solution 1:[1]

What you are looking for is called KeyPathComparator. You can pass as many properties as needed when sorting your collection:

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Leo Dabus