-2

I'm trying to add part of a large NSArray to another NSArray. However, I'm doing something wrong since it keeps throwing errors.

This is the specific code:

@property (nonatomic, strong) NSMutableArray *searches;
@property (nonatomic, strong) NSMutableArray *chosenResult;

...bit further down...

for (NSString *string in self.searches[indexPath.row]) {
    [self.chosenResult addObject:string];
}

This is the error:

'NSInvalidArgumentException', reason: '-[Search countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0x7a1710d0'
user4334509
  • 125
  • 2
  • 10
  • 1
    possible duplicate of [How can I debug 'unrecognized selector sent to instance' error](http://stackoverflow.com/questions/25853947/how-can-i-debug-unrecognized-selector-sent-to-instance-error) – Hot Licks Jan 19 '15 at 22:12
  • It's really not. I know what the error means, I just don't know how to pass the content of the array at that point to another array. – user4334509 Jan 19 '15 at 22:14
  • Well, for us to have a clue as to how to help you, you'd have to reveal the structure of your source array, including the structure of the `Search` class which you appear to be using instances of. – Hot Licks Jan 19 '15 at 22:16
  • 2
    (You clearly don't know what "unrecognized selector" means if you don't realize that there's a `Search` instance in the mix.) – Hot Licks Jan 19 '15 at 22:19

2 Answers2

2

It looks like you just don't need the fast enumeration loop, because you already have the index into the array:

[self.chosenResult addObject:self.searches[indexPath.row]];

The error that you see is because the fast enumeration loop is expecting some collection, like an array, but you're actually providing it a Search object which doesn't implement the fast enumeration methods.

Wain
  • 118,658
  • 15
  • 128
  • 151
2

You have a disconnect between what you think you have in your data structure and what you actually have in your data structure. The error is telling you that you are trying to send the message countByEnumeratingWithState:objects:count: (a fast enumeration method) to a Search object.

That tells us that your self.searches array contains Search objects, not dictionaries as you say it does. (Or at least that the object at the target index is a Search object. Objects at other indexes could be some other type...) I suggest doing some more debugging to figure out why the array contains something different than you think it does.

Duncan C
  • 128,072
  • 22
  • 173
  • 272