This is my code:
NSString *newString = @"new value";
[breakdownCollection objectAtIndex:i] = newString;
breakdownCollection is an NSArray of multiple strings. I need to access a given string contained in the array via index number, and change the string’s content to that of the new string. Note that I cannot simply replace the string with the new one, I am only trying to replace its contents.
When I try to do this, however, I get an “lvalue required as left operand of assignment” error.
Any help with this issue would be very much appreciated!
The error you get is because you wrote the assignement instruction incorrectly. That is, you cannot assign
newStringto[breakdownCollection objectAtIndex:i].Also, you won’t be able to do it this way. Instead, in order to modify string object content, use
NSMutableString, which provides methods to do so (NSStringare immutable objects).So, for example you should try :
assuming you put
NSMutableStringintobreakdownCollection.PS : in order to change the object at the index
i, you have to useNSMutableArrayinstead ofNSArray, and then call :Good luck !
NSMutableString class reference
NSMutableArray class reference