NSInteger timeNum = time;
NSMutableArray theResultArray = [[NSMutableArray alloc] init];
[theResultArray insertObject:[NSNumber numberWithInt:timeNum] atIndex:rightIndex];
This is the way we开发者_如何学Go do to insert NSInteger to array. How to i do it for NSString?
It's easier because you don't have to encapsulate the integer:
[theResultArray insertObject:myNSString atIndex:rightIndex];
Hope that helps.
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.
精彩评论