开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜