Array

struct Array<Element> : _DestructorSafeContainer

This extension adds some useful functions to Array.

  • A Bool value indicating whether the collection is not empty.

    Declaration

    Swift

    public var isNotEmpty: Bool { get }

    Return Value

    Returns a Bool value indicating whether the collection is not empty.

  • Simulates the array as a circle. When it is out of range, begins again.

    Declaration

    Swift

    public func circleObject(at index: Int) -> Element

    Parameters

    index

    The index.

    Return Value

    Returns the object at a given index.

  • Randomly selects an element from self and returns it.

    Declaration

    Swift

    public func random() -> Element

    Return Value

    An element that was randomly selected from the array.

  • Removes the element from self that is passed in.

    Declaration

    Swift

    public mutating func remove(_ object: Element)

    Parameters

    object

    The element that is removed from

  • Get the object at a given index in safe mode (nil if self is empty or out of range).

    Declaration

    Swift

    public func safeObject(at index: Int) -> Element?

    Parameters

    index

    The index.

    Return Value

    Returns the object at a given index in safe mode (nil if self is empty or out of range).

  • Move object from an index to another.

    Declaration

    Swift

    public mutating func swap(from fromIndex: Int, to toIndex: Int)

    Parameters

    fromIndex

    The start index.

    toIndex

    The end index.