When I convert an array element to an integer using this statement
int test=(int)[myArray objectAtIndex:2];
later use of “test” passed to other commands fails.However, this statement works
int test=[[myArray objectAtIndex2]intValue];
What is the difference between these two types of conversion?
The first is a cast. You’re taking the object and casting it to an int, which will give you an int that contains the address of the object (and under 64-bit it will only contain the low 32 bits of the address). This isn’t at all what you want.
The second is a method call for
-intValue, which is implemented byNSNumber(andNSString) to return theintthat theNSNumber(orNSString) object represents. This is (presumably) what you actually want.