0
votes

as the title says I'm having an issue with taking objects out of an array, flipping them, and putting them back in. Below is the code I currently have that ends in this error

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI removeObjectsAtIndexes:]: unrecognized selector sent to instance

I was wondering if anyone knew how to fix this? Here's a little more info on how I have it set up:

The object "PEG" is an NSString that displays "-0.6", "4.36"

GlobalSortedArray is an array filled with dictionary containing the PEG object

//Declare variables
NSMutableArray *negArray = [[NSMutableArray alloc]init];
NSMutableIndexSet *index = [[NSMutableIndexSet alloc]init];
int negcount = 0;
NSDictionary *forLoopDict;


for (forLoopDict in globalSortedArray)
      {
          if ([[forLoopDict objectForKey:@"PEG"] hasPrefix:@"-"])
          {
              [index addIndex:negcount];
          }
          negcount++;
      }


NSLog(@"%@", negArray);

//    Removes objects from main array. This is what seems to be messing up.
[globalSortedArray removeObjectsAtIndexes:index];

//    Reverses the array
NSArray* reversedArray = [[negArray reverseObjectEnumerator] allObjects];

//    insters them back into the main array
[globalSortedArray insertObjects:negArray atIndexes:0];
2
Are you 100% sure that globalSortedArray is an NSMutableArray and not a standard NSArray and that it is instantiated already when you call the method? - Dare
__NSArrayI -> immutable array, __NSArrayM -> Mutable array - vikingosegundo
Unlike forum sites, we don't use "Thanks", or "Any help appreciated", or signatures on Stack Overflow. See "Should 'Hi', 'thanks,' taglines, and salutations be removed from posts?. BTW, it's "Thanks in advance", not "Thanks in advanced". - John Saunders

2 Answers

1
votes

You are trying to remove an item from globalSortedArray. It is an NSArray and not mutable.

0
votes

globalSortedArray as NSmutableArray

NSArray -- > NSMutableArray