jckly
jckly

Reputation: 851

'-[__NSArrayM _fastCStringContents:]: unrecognized selector sent to instance

I keep getting a unrecognized selector when I try to add an object to my mutable array, I'm trying to add and remove items to a mutable array when a cell is selected in my tableview, here is my code:

@interface SomeViewController
  @property (nonatomic, strong) NSMutableArray *selectedItems;
@end

View did load:

-(void)viewDidLoad {

    [super viewDidLoad];

    self.selectedItems = [[NSMutableArray alloc] init];
}

Selecting cell:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    MyCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];

    [self.selectedItems addObject:[NSString stringWithFormat:@"%@", cell.contactID]];

Contact Id attribute on MyCell file is:

@property (strong, nonatomic) NSString *contactID;

I keep getting this error:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM _fastCStringContents:]: unrecognized selector sent to instance 0x7fc3dd1091b0'

Upvotes: 2

Views: 4205

Answers (3)

Alex Nazarov
Alex Nazarov

Reputation: 1218

It could be when you pass array directly into NSLog, like NSLog(array), instead of NSLog(@"%@", array)

Upvotes: 0

Jamshed Alam
Jamshed Alam

Reputation: 12844

Try to implement it in normal UITableView. If you get no issue then its problem to yours MyCell. Check with mutable or copy array also. Try to NSLog the cell.contactID

Upvotes: 0

gnasher729
gnasher729

Reputation: 52530

Somewhere you have an object that you believe is a string, when in reality it is a mutable array - that's what the error message says. Set a breakpoint on exceptions, that should tell you exactly where it happens, and then find the array that you believe is a string.

Upvotes: 8

Related Questions