SortDescriptor

public struct SortDescriptor<T>

a comparator used to compare two objects

  • Initialize a sort descriptor with a custom comparator

    Declaration

    Swift

    public init<V: Comparable>(_ keyPath: KeyPath<T, V>, ascending: Bool = true)

    Parameters

    keyPath

    A keypath for the type being sorted

    ascending

    If the comparison should order ascending

  • Initialize a sort descriptor with a custom comparator

    Declaration

    Swift

    public init(_ comparator: @escaping ((T, T) -> SortDescriptorResult))

    Parameters

    comparator

    A comparator returning a comparison result

  • Compare two objects

    Declaration

    Swift

    public func compare(_ a: T, to b: T) -> SortDescriptorResult

    Parameters

    a

    The first object

    b

    The second object

    Return Value

    A SortDescriptorResult for the two objects.