Subscript

subscript(_:)

Returns the object at the specified index.

Declaration

subscript(idx: Int) -> Any { get }

Parameters

idx

An index within the bounds of the array.

Return Value

The object located at index.

Discussion

This method has the same behavior as the object(at:) method.

If index is beyond the end of the array (that is, if index is greater than or equal to the value returned by count), an rangeException is raised.

You shouldn’t need to call this method directly. Instead, this method is called when accessing an object by index using subscripting.

id value = array[3]; // equivalent to [array objectAtIndex:3]

See Also

Querying an Array

func contains(Any) -> Bool

Returns a Boolean value that indicates whether a given object is present in the array.

var count: Int

The number of objects in the array.

var firstObject: Any?

The first object in the array.

var lastObject: Any?

The last object in the array.

func object(at: Int) -> Any

Returns the object located at the specified index.

func objects(at: IndexSet) -> [Any]

Returns an array containing the objects in the array at the indexes specified by a given index set.

func objectEnumerator() -> NSEnumerator

Returns an enumerator object that lets you access each object in the array.

func reverseObjectEnumerator() -> NSEnumerator

Returns an enumerator object that lets you access each object in the array, in reverse order.