3

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 :)

4 Answers 4

11

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];
Sign up to request clarification or add additional context in comments.

Comments

2

Here's an example of how to do this:

int yourInt = 5;
[myMutableArray addObject:[NSNumber numberWithInt:yourInt]];

Comments

0

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];

Comments

0

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++;

}

Comments

Your Answer

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.

Ask question

Explore related questions

See similar questions with these tags.