Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine an array index in Objective C?

I have two arrays in Objective C and I need to find what index something is so I can insert it in the same place. For instance, lets say I have a "name array" and an "age array". How do I find out what index "charlie" is in the "name array" so I know where to insert his age in the "age" array?

Thanks

like image 581
Xcoder Avatar asked Jul 16 '09 02:07

Xcoder


People also ask

How do you find the index of an array?

To find the position of an element in an array, you use the indexOf() method. This method returns the index of the first occurrence the element that you want to find, or -1 if the element is not found. The following illustrates the syntax of the indexOf() method.

What is NSArray in Objective C?

An object representing a static ordered collection, for use instead of an Array constant in cases that require reference semantics.

What is the index of an array?

The index indicates the position of the element within the array (starting from 1) and is either a number or a field containing a number.

What is the Objective of array?

The purpose of an array is to store multiple pieces of data of the same type together.


1 Answers

-[NSArray indexOfObject:] would seem to be the logical choice.

like image 104
Chuck Avatar answered Sep 19 '22 05:09

Chuck