Collection

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

    Returns the element at the specified index or nil if not exists.

    Example:

    let array = [1, 2, 3]
    array[100] -> crash
    array[safe: 100] -> nil
    

    Declaration

    Swift

    public subscript(safe index: Index) -> Element? { get }

    Parameters

    index

    the index of the desired element.

  • Mechanica

    Example:

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

    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.