Can someone see where the error is here…
NSArray *arr = [str componentsSeparatedByString:@","];
NSString *inputStr = [arr objectAtIndex:0];
NSString *trimmedStr = [inputStr stringByTrimmingCharactersInSet:
[NSCharacterSet whitespaceAndNewlineCharacterSet]];
[[arr objectAtIndex:0] replaceObjectAtIndex:0 withObject:trimmedStr];
output:
-[__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'
EDIT: added extra line to show that the array has been declared and populated.
So as said in comment below, when I replace the line:
[[arr objectAtIndex:0] replaceObjectAtIndex:0 withObject:trimmedStr];
with:
[arr replaceObjectAtIndex:0 withObject:trimmedStr];
Xcode error(before running):
No visible @interface for 'NSArray' declares the selector 'replaceObjectAtIndex:withObject'
This is whats wrong:
what you actually want to do is:
you were sending replaceObjectAtIndex to the string in the array ([arr objectAtIndex:0]) which obviously wont work out. Send that message to the (mutable) array and it’ll replace the string with the new one.
For your next question: Tell us more about what you are trying to do etc, and dont limit yourself to less than 10 words. The more detail you give, the more help you will get.