Instance Method


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


func contains(_ anObject: Any) -> Bool



An object to look for in the array.

Return Value

true if anObject is present in the array, otherwise false.


Starting at index 0, each element of the array is checked for equality with anObject until a match is found or the end of the array is reached. Objects are considered equal if isEqual(_:) returns true.

To determine if the array contains a particular instance of an object, you can test for identity rather than equality by calling the indexOfObjectIdentical(to:) method and comparing the return value to NSNotFound.

See Also

Querying an 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.

subscript(Int) -> Any

Returns the object 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.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software