Array

class Array

A heterogeneous array which can store values of differing types. The same value can appear repeatedly within an array.

  • Number of elements in the array.

    Declaration

    var count: Array { get }
  • true if the array contains 0 elements and false otherwise.

    Declaration

    var isEmpty: Array { get }
  • Compares two values for equality.

    The equals function is invoked using infix notation as in the following code snippet: lhs == rhs.

    Declaration

    func equals(_ lhs: Array) -> Bool

    Parameters

    lhs

    A value.

    rhs

    Another value.

    Return Value

    true if the lhs and rhs are equal, false otherwise.

  • Determines whether the array contains the specified element.

    Declaration

    func contains(_ element: Any) -> Bool

    Parameters

    element

    The element to search for.

    Return Value

    true if the array contains the element, false otherwise.

  • Filters the elements of the array.

    Declaration

    func filter(_ closure: Function) -> Array

    Parameters

    closure

    Closure used to determine whether an element should be included.

    Return Value

    A new array with the original elements except those for which closure returns false.

  • Builds a string by joining string representations of all the elements in the array separated by the given separator.

    Declaration

    func joined(separator: String) -> String

    Parameters

    separator

    Separator inserted between elements.

    Return Value

    A string with all the elements of the array joined by separator.

  • Transforms the elements of the array with a closure.

    Declaration

    func map(_ closure: Function) -> Array

    Parameters

    closure

    The closure used to transform each element.

    Return Value

    A new array where each element has been transformed by the closure.

  • Reverses the array.

    Declaration

    func reversed() -> Array

    Return Value

    A new array where the elements are reversed.

  • Sorts the array.

    Declaration

    func sorted(by areInIncreasingOrder: Function) -> Array

    Parameters

    areInIncreasingOrder

    A closure which accepts the values of two elements and returns true if the first element should be ordered before the second and false otherwise.

    Return Value

    A new array where elements are sorted.

  • Appends an element to the array.

    Declaration

    func appending(_ x: Any) -> Array

    Parameters

    x

    The new element.

    Return Value

    A new array with x appended.

  • Returns a new array obtained by removing the first element.

    Declaration

    func dropFirst() -> Array

    Return Value

    A new array where the first element has been removed.

  • Returns a new array obtained by removing the last element.

    Declaration

    func dropLast() -> Array

    Return Value

    A new array where the last element has been removed.