Returns the lowest index whose corresponding array value is equal to a given object.
SDKs
- iOS 2.0+
- macOS 10.0+
- tvOS 9.0+
- watchOS 2.0+
Framework
- Foundation
Declaration
func index(of anObject: Any) -> Int
Parameters
anObject
An object.
Return Value
The lowest index whose corresponding array value is equal to an
. If none of the objects in the array is equal to an
, returns NSNot
.
Discussion
Starting at index 0
, each element of the array is passed as an argument to an is
message sent to an
until a match is found or the end of the array is reached. Objects are considered equal if is
(declared in the NSObject
protocol) returns true
.