/ / Obj-C: pridanie objektov do indexov poľa - Objective-C, polia

Obj-C: pridajte objekty do indexov poľa - object-c, polia

Snažím sa pridávať objekty do určitých indexov poľa do nového poľa. Našiel som riešenie, ale existuje na to elegantnejší spôsob? Toto mám.

 NSMutableArray *objectsToAdd = [[NSMutableArray alloc]init];

for (NSIndexPath *indexPath in self.selectedIndexes)
{
for (Object *object in self.unsortedObjects) {
if (indexPath.row == [self.unsortedObjects indexOfObject:object]) {
[objectsToAdd addObject:object];
}
}
}

odpovede:

0 pre odpoveď č. 1

Verím self.selectedIndexes je NSArray alebo NSMutableArray. Dúfam, že pomôžeme

NSMutableArray *objectsToAdd = [[NSMutableArray alloc]init];
for (NSIndexPath *indexPath in self.selectedIndexes)
{
if (indexPath.row < [self.unsortedObjects count]) {
[objectsToAdd addObject:self.unsortedObjects[indexPath.row]] ;
}
}