有人可以看到错误在哪里...
NSArray *arr = [str componentsSeparatedByString:@","];
NSString *inputStr = [arr objectAtIndex:0];
NSString *trimmedStr = [inputStr stringByTrimmingCharactersInSet:
[NSCharacterSet whitespaceAndNewlineCharacterSet]];
[[arr objectAtIndex:0] replaceObjectAtIndex:0 withObject:trimmedStr];
输出:
-[__NSCFString replaceObjectAtIndex:withObject:]:
unrecognized selector sent to instance 0x68a8eb0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: '-[__NSCFString replaceObjectAtIndex:withObject:]:
unrecognized selector sent to instance 0x68a8eb0'
编辑:添加了额外的行以显示该数组已被声明和填充。
正如下面评论中所说,当我替换该行时:
[[arr objectAtIndex:0] replaceObjectAtIndex:0 withObject:trimmedStr];
和:
[arr replaceObjectAtIndex:0 withObject:trimmedStr];
Xcode 错误(运行前):
No visible @interface for 'NSArray' declares the selector 'replaceObjectAtIndex:withObject'