Clearing rather than releasing a NSMutableString
I've got a rather large loop that gets a string, does something to it, than goes onto the next one. I was originally relea开发者_如何学Gosing it then reallocating it but thought that is a bit of waste of resources but can't figure out how to just clear it out to reuse it.
One way would be [myString setString: @""]
.
The selected solution will crash with the following error:
'Attempt to mutate immutable object with setString:'
This worked for me instead:
self.myString = [NSMutableString stringWithString:@""];
make sure you synthesize myString in your class.
精彩评论