views:

36

answers:

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?

+3  A: 

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

[theResultArray insertObject:myNSString atIndex:rightIndex];

Hope that helps.

Jorge Israel Peña
+1  A: 

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.

JeremyP