2
NSInteger timeNum = time; 
NSMutableArray theResultArray = [[NSMutableArray alloc] init];
[theResultArray insertObject:[NSNumber numberWithInt:timeNum] atIndex:rightIndex]; 

This is the way we do to insert NSInteger to array. How to i do it for NSString?

2 Answers 2

3

It's easier because you don't have to encapsulate the integer:

[theResultArray insertObject:myNSString atIndex:rightIndex];

Hope that helps.

Sign up to request clarification or add additional context in comments.

Comments

2

It's exactly the same:

NSString* myNSString = @"foo"; 
NSMutableArray theResultArray = [[NSMutableArray alloc] init];
[theResultArray insertObject:myNSString atIndex:rightIndex];

Be aware that if you try to insert an object in a position that doesn't exist (i.e. if rightIndex > [theResultArray count]), you will get an exception. In the example above, the only legal value for rightIndex is 0 because the array is empty.

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.