Using NSArray for C-type int comparisons
- by Andrew Barinov
I would like to iterate through an NSArray of ints and compare each one to a specific int. All ints are C type ints.
The code I am using is as follows:
-(int)ladderCalc: (NSArray*)amounts: (int)amount
{
int result;
for (NSUInteger i=0; i< [amounts count]; i++)
{
if (amount < [amounts objectAtIndex:i]);
{
// do something
}
// do something
}
}
However I get an error when comparing the int amount to the result of [amounts objectAtIndex:i] because you cannot compare id to int. Why is the id involved in this case? Shouldn't objectAtIndex just return the object at the index specified? Is it possible to cast the object returned to an C int and then do the comparison?
Or should I just dispense with NSArray and do this type of thing in C?