SortDescriptor
SortDescriptor sorts records by keys (NSSortDescriptor in shape). Filter
with a Predicate, then sort with descriptors:
what a table does to its rows. From 0.72.
#import "SortDescriptor.xc" // not in the Foundation umbrella: import it by nameOverview
Section titled “Overview”Array* rows = SortDescriptor.sorted(people, SortDescriptor.list2( SortDescriptor.withKey(String.withCString("age"), false), // oldest first SortDescriptor.withKey(String.withCString("name"), true))); // then by nameA descriptor names a key (a dotted path through nested Maps, as a predicate reads one), a direction, and whether Strings compare ignoring ASCII case. A list of descriptors sorts by the first and breaks ties with the next.
Values order as a predicate compares them
(Predicate.compareValues): Numbers as numbers,
with Strings that hold numbers; Strings by bytes. A missing or null value, or
one with no order against the other, sorts before every other value when
ascending, and after when descending.
The sort is stable: records every descriptor finds equal keep their order.
Topics
Section titled “Topics”Describing · withKey · key / ascending / caseInsensitive · reversed · list1 / list2
Sorting · sorted · sortedWith · compare / compareValues
Describing
Section titled “Describing”withKey
Section titled “withKey”static SortDescriptor* withKey(String* key, bool ascending)key / ascending / caseInsensitive
Section titled “key / ascending / caseInsensitive”String* key;bool ascending;bool caseInsensitive;Public fields.
reversed
Section titled “reversed”SortDescriptor* reversed(void)A copy with the direction turned round: for a column header clicked again.
list1 / list2
Section titled “list1 / list2”static Array* list1(SortDescriptor* a)static Array* list2(SortDescriptor* a, SortDescriptor* b)A list of one or two descriptors, for the common cases; any Array of
descriptors will do.
Sorting
Section titled “Sorting”sorted
Section titled “sorted”static Array* sorted(Array* items, Array* descriptors)A sorted copy of items (Maps).
sortedWith
Section titled “sortedWith”static Array* sortedWith(Array* items, Array* descriptors, callback read Object*(Object* item, String* key))The same for any objects, reading each key through read.
compare / compareValues
Section titled “compare / compareValues”i8 compare(Object* a, Object* b)i8 compareValues(Object* a, Object* b)How two records, or two values, order under this one descriptor: -1, 0 or 1.