Anyone know what cause this crash:"[__NSArrayI replaceObjectAtIndex:withObject:]: unrecognized selector"?

1.1k views Asked by At

Recently I use NSTextTable draw table. I want change some attribute of selected block,so save selected paragraphs into dictionary. After I copy the block of paragraph, once I call method [NSTextTableBlock setBorderColor:], raise an error:

-[__NSArrayI replaceObjectAtIndex:withObject:]: unrecognized selector sent to instance 0x6000002442c0

I try many times, finally found a phenomenon, which is if I don't copy block, setBorderColor: is OK. Anyone know relation of [NSTextTableBlock copy] and this error, why [NSTextTableBlock setBorderColor:] cause this error? I'm quite confuse about this error. Thanks in advance.

1

There are 1 answers

1
lindon fox On BEST ANSWER

NSArray does not have the selector replaceObjectAtIndex:withObject: (so you can't call it). You are actually trying to modify an NSArray which can not be modified like that. You probably want NSMutableArray instead. You can create an NSMutableArray from an NSArray, call your method and then replace your reference to the original array like this:

NSMutableArray *mutableArray = [NSMutableArray arrayWithArray:array];
[mutableArray replaceObjectAtIndex:index withObject:object];
array = mutableArray;//now the array has been "updated"