Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
I have NSMutableArray having values 10,15,26,28. I want to store them into another array as an integer form how do i store them. Thanks :)
NSMutableArray
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];
Add a comment
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];...
[NSNumber numberWithInteger:10];
You can then get the int value back with [aNSNumberObject intValue];
[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++; }
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.