Próbuję dodać obiekty w określonych indeksach tablicy do nowej tablicy. Znalazłem rozwiązanie, ale czy jest na to bardziej elegancki sposób? Oto, co mam.
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];
}
}
}
Odpowiedzi:
0 dla odpowiedzi № 1wierzę self.selectedIndexes
to jest NSArray
lub NSMutableArray
. Mam nadzieję, że pomogę
NSMutableArray *objectsToAdd = [[NSMutableArray alloc]init];
for (NSIndexPath *indexPath in self.selectedIndexes)
{
if (indexPath.row < [self.unsortedObjects count]) {
[objectsToAdd addObject:self.unsortedObjects[indexPath.row]] ;
}
}