How to store integer value into an NSMutableArray in iphone
I have NSMutableArray
having values 10,15,26,28. I want to store them into another array as an开发者_JAVA百科 integer form how do i store them.
Thanks :)
here how to add
[array addObject:[NSNumber numberWithInt:10]];
you can get the integer value like
//assuming array has nsnumber/nsstring objects.
[[array objectAtIndex:index] intValue];
Here's an example of how to do this:
int yourInt = 5;
[myMutableArray addObject:[NSNumber numberWithInt:yourInt]];
You can't store C types in a NSMutableArray, you can only store objects.
Create NSNumber's from your int values with [NSNumber numberWithInteger:10];
...
You can then get the int value back with [aNSNumberObject intValue];
If you want to store integers in an array it has to be a C array:
#define C_ARRAY_MAX_SIZE 10
int cTab[C_ARRAY_MAX_SIZE];
int i=0;
for (NSNumber* n in yourMutableArray) {
cTab[i] = [n intValue];
i++;
}
精彩评论