How to add data to NSMutableArray by manually assigning an index?

Is there a way to manually control the index with which we want to add our data using NSMutableArray? In PHP, for example, we can do:

$foo[2] = "fafa";
$foo[8] = "haha";

Is it possible to perform manual indexing assignment to NSMutableArray?

+3
source share
4 answers

Just because it’s not entirely clear to me that TeamStar wants a sparse array, I just mentioned that you can assign objects to specific indices at NSMutableArray- as long as the array is already long enough - using -replaceObjectAtIndex:withObject:other methods -replace….

+2
source

NSMutableArray - , . 0 - 1, insertObject:atIndex: ( ), ( addObject:).

, NSMapTable - NSMutableDictionary, NSNumber ( drewag).

: Cocoa

+4

, . NSMutableDictionary. NSNumbers .

+2
- (void)insertObject:(id)anObject atIndex:(NSUInteger)index

NSRangeException, .

+1

All Articles