MutableCollection

public extension MutableCollection
public extension MutableCollection where Self: RandomAccessCollection
  • SwifterSwift: Assign a given value to a field keyPath of all elements in the collection.

    Declaration

    Swift

    mutating mutating func assignToAll<Value>(value: Value, by keyPath: WritableKeyPath<Element, Value>)

    Parameters

    value

    The new value of the field

    keyPath

    The actual field of the element

Available where Self: RandomAccessCollection

  • SwifterSwift: Sort the collection based on a keypath and a compare function.

    Declaration

    Swift

    mutating mutating func sort<T>(by keyPath: KeyPath<Element, T>, with compare: (T, T) -> Bool)

    Parameters

    keyPath

    Key path to sort by. The key path type must be Comparable.

    compare

    Comparation function that will determine the ordering.

  • SwifterSwift: Sort the collection based on a keypath.

    Declaration

    Swift

    mutating mutating func sort<T>(by keyPath: KeyPath<Element, T>) where T : Comparable

    Parameters

    keyPath

    Key path to sort by. The key path type must be Comparable.

  • SwifterSwift: Sort the collection based on two key paths. The second one will be used in case the values of the first one match.

    Declaration

    Swift

    mutating func sort<T: Comparable, U: Comparable>(by keyPath1: KeyPath<Element, T>,
                                                     and keyPath2: KeyPath<Element, U>)

    Parameters

    keyPath1

    Key path to sort by. Must be Comparable.

    keyPath2

    Key path to sort by in case the values of keyPath1 match. Must be Comparable.

  • SwifterSwift: Sort the collection based on three key paths. Whenever the values of one key path match, the next one will be used.

    Declaration

    Swift

    mutating func sort<T: Comparable, U: Comparable, V: Comparable>(by keyPath1: KeyPath<Element, T>,
                                                                    and keyPath2: KeyPath<Element, U>,
                                                                    and keyPath3: KeyPath<Element, V>)

    Parameters

    keyPath1

    Key path to sort by. Must be Comparable.

    keyPath2

    Key path to sort by in case the values of keyPath1 match. Must be Comparable.

    keyPath3

    Key path to sort by in case the values of keyPath1 and keyPath2 match. Must be Comparable.