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 } -
trueif the array contains 0 elements andfalseotherwise.Declaration
var isEmpty: Array { get } -
Compares two values for equality.
The
equalsfunction is invoked using infix notation as in the following code snippet:lhs == rhs.Declaration
func equals(_ lhs: Array) -> BoolParameters
lhsA value.
rhsAnother value.
Return Value
trueif thelhsandrhsare equal,falseotherwise. -
Determines whether the elements of the array are identical.
Declaration
func areIdentical() -> BoolReturn Value
trueif all the elements in the array are identical,falseotherwise. -
Determines whether the array contains the specified element.
Declaration
func contains(_ element: Any) -> BoolParameters
elementThe element to search for.
Return Value
trueif the array contains the element,falseotherwise. -
Appends the elements of
arrayto the array.Declaration
func concatenate(_ array: Array) -> ArrayParameters
arrayThe array whose elements are added.
Return Value
A new array formed by appending the elements of
arrayto the original array. -
Filters the elements of the array.
Declaration
func filter(_ closure: Function) -> ArrayParameters
closureClosure used to determine whether an element should be included.
Return Value
A new array with the original elements except those for which
closurereturnsfalse. -
Builds a string by joining string representations of all the elements in the array separated by the given separator.
Parameters
separatorSeparator 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) -> ArrayParameters
closureThe 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() -> ArrayReturn Value
A new array where the elements are reversed.
-
Sorts the array.
Declaration
func sorted(by areInIncreasingOrder: Function) -> ArrayParameters
areInIncreasingOrderA closure which accepts the values of two elements and returns
trueif the first element should be ordered before the second andfalseotherwise.Return Value
A new array where elements are sorted.
-
Appends an element to the array.
Declaration
func appending(_ x: Any) -> ArrayParameters
xThe new element.
Return Value
A new array with
xappended. -
Returns a new array obtained by removing the first element.
Declaration
func dropFirst() -> ArrayReturn Value
A new array where the first element has been removed.
-
Returns a new array obtained by removing the last element.
Declaration
func dropLast() -> ArrayReturn Value
A new array where the last element has been removed.
-
Determines the index of the first occurence of
elementin the array.Declaration
func firstIndex(of element: Any) -> DoubleParameters
elementThe element to search for.
Return Value
The index of the first occurence of
elementin the array, ornilif the element is not contained within the array.