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 andfalse
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
lhsA value.
rhsAnother value.
Return Value
true
if thelhs
andrhs
are equal,false
otherwise. -
Determines whether the elements of the array are identical.
Declaration
func areIdentical() -> Bool
Return Value
true
if all the elements in the array are identical,false
otherwise. -
Determines whether the array contains the specified element.
Declaration
func contains(_ element: Any) -> Bool
Parameters
elementThe element to search for.
Return Value
true
if the array contains the element,false
otherwise. -
Appends the elements of
array
to the array.Declaration
func concatenate(_ array: Array) -> Array
Parameters
arrayThe array whose elements are added.
Return Value
A new array formed by appending the elements of
array
to the original array. -
Filters the elements of the array.
Declaration
func filter(_ closure: Function) -> Array
Parameters
closureClosure used to determine whether an element should be included.
Return Value
A new array with the original elements except those for which
closure
returnsfalse
. -
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) -> Array
Parameters
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() -> Array
Return Value
A new array where the elements are reversed.
-
Sorts the array.
Declaration
func sorted(by areInIncreasingOrder: Function) -> Array
Parameters
areInIncreasingOrderA closure which accepts the values of two elements and returns
true
if the first element should be ordered before the second andfalse
otherwise.Return Value
A new array where elements are sorted.
-
Appends an element to the array.
Declaration
func appending(_ x: Any) -> Array
Parameters
xThe 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.
-
Determines the index of the first occurence of
element
in the array.Declaration
func firstIndex(of element: Any) -> Double
Parameters
elementThe element to search for.
Return Value
The index of the first occurence of
element
in the array, ornil
if the element is not contained within the array.