Home > database >  How to sort array of data from one class by criteria of String from another class?
How to sort array of data from one class by criteria of String from another class?

Time:04-27

How to compare two classes datas?

CodePudding user response:

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))
  • Related