I have an NSString that I’d like to append a { at the beginning of it.
NSMutableString *str = [[NSMutableString alloc] initWithString:@"{"];
[str stringByAppendingString:extracted];
This returns str with only {. Why is that? Objective-C is VERY frustrating with how it provides many ways of doing the same thing, yet for situations a different way is required.
I tried doing [NSMutableString string] and appending { then extracted and it still does not work. Why is this not working and what should I do?
stringByAppendingStringreturns a new string, it does not modify the old string.All functions that begins with
stringWithorarrayWithetc. create new objects rather than modifying old objects.To acheive what you want, a simpler solution is:
or: