0

please tell me that can we create an array of imteger in objective c i am a new iphone programmer and i am creating an aray which can take an integer from a view (at 0th position)and pass that array to next view and then again put an integer to it (at 1st position) and so on.... please help because it does not accept integer value

2 Answers 2

3

What you want to do is add NSNumbers to the array.

[myArray addObject:[NSNumber numberWithInt:myInteger]];

And to access the integer from the array

int myInteger = [[myArray objectAtIndex:myIndex] intValue];
Sign up to request clarification or add additional context in comments.

Comments

2

You can only store objects in NSArrays, not primitives (like int, float, NSInteger, etc.), which is probably what you're trying. Use NSNumber instead.

2 Comments

but if i use NSNumber *myInt = [NSNumber numberWithInt:sender.tag]; [myarray addObject:myInt]; it show null on oth position of my array i have already declared my array no compilation problen is there......
You'll have to rephrase your question. I am having trouble understanding. If you are trying to add objects to an NSArray after initialization, that will not work, as it is not a mutable class. You will want to use NSMutableArray instead.

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.