I have an NSMutableArray called george. It has NSInteger values inside: 12, 23, 54, 34, 45.
Now I have a string called unitID its made of a letter and a number eg. t00, e01, t02, e03, t04
what I’m doing is:
-(int)getSpawnAmount:(NSString *)unitID
{
typeString = [unitID substringWithRange:NSMakeRange(0,1)];
numberString = [unitID substringWithRange:NSMakeRange(1,2)];
return [[george objectAtIndex:[numberString integerValue]] integerValue];
}
I know that objectAtIndex returns an “id” and im not sure whether im doing it the right way to get the integer values.
Anyway my question is how do I get NSInteger values from my NSMutableArray using objectAtIndex?
Thanks in advance.
My array was in another class and instead of referencing it I was creating a new NSMutableArray, which was blank. My code works fine now. Thanks for your answers.
The safe way could be to use reflection on type id; so you will be able to put some errorhandling inside.
Otherwise you could cast type id to a NSNumber and so to “any” other type, e.g. int.