Contents

object(withID:)

Returns the object in the array with the given identifier.

Declaration

func object(withID identifier: Any) -> Any

Parameters

  • identifier:

    The identifier of one of the receiver’s objects.

Return Value

A reference to the identified object or nil if could not be found.

Discussion

This method is provided as an alternative to object(at:) for applications where an identifier is available instead of (or in addition to) an index. A unique ID is generally more stable than an index. For example, it may be more useful to identify a contact in Address Book by its identifier (which doesn’t change over time) than by its index in the list of contacts (which can change as contacts are added or removed).

See Also

Getting Objects in the Array