Collection

protocol Collection : Sequence where Self.SubSequence : Collection
  • Mechanica

    Declaration

    Swift

    public func at(_ index: Index) -> Element?

    Parameters

    index

    the index of the desired element.

    Return Value

    The element at a given index or nil if not exists. Example:

    let array = [1, 2, 3] array[100] -> crash array.at(100) -> nil

  • Mechanica

    Returns the first index where the specified value appears in the collection. After using firstIndex(of:) to find the last position of a particular element in a collection, you can use it to access the element by subscripting.

    Note

    Same as index(of:).

    See also

    index(of:)

    Declaration

    Swift

    public func firstIndex(of element: Element) -> Self.Index?

    Parameters

    element

    Index of the first element found (if any).

  • Mechanica

    Returns the last index where the specified value appears in the collection. After using lastIndex(of:) to find the last position of a particular element in a collection, you can use it to access the element by subscripting.

    Declaration

    Swift

    public func lastIndex(of element: Element) -> Self.Index?

    Parameters

    element

    Index of the last element found (if any).

  • Mechanica

    Returns a random element from self.

    Declaration

    Swift

    public func random() -> Element