Algorithms โฉ Sorting โฉ
seq.sorted()
seq.sorted(by:)
seq.sorted(_:) - sort by keypaths with ascending/descending orders
the sorted(by:) function is actually 2 different functions.
sorted(by:)
one requires Comparable and uses < internally.
Comparable
<
the other lets you specify the sorting logic directly (Comparable conformance not required).
... this convenience sorting by keyPath would still require 2 functions.
keyPath
๐ Reference default comparison function as a function parameter
Sundell โฉ Sorting Swift collections โญ๏ธ
Sarun โฉ
Different ways to sort an array of strings in Swift
How to sort by multiple properties in Swift
Standard Lib โฉ Collections โฉ Sequence
sorted() - Element: Comparable
Swift โฉ Array โฉ
sort() - sort in place. Element: Comparable
sort(by:) - sort in place.
Comparable Enums
Last updated 2 years ago