seq.sorted(by:)

// sorted(by:)
func sorted(
  by areInIncreasingOrder: (Self.Element, Self.Element) throws -> Bool
) rethrows -> [Self.Element]

用這個方法的優點是:Self.Element 不需要Comparable

// ⭐️ 1. sort a Sequence using `sorted(by:)` method.
//     - always returns an Array.
let sorted = todolist.sorted { a, b in a.date < b.date }

Last updated

Was this helpful?