8

我有一个相当大的循环,它获取一个字符串,对其进行处理,然后进入下一个。我最初是发布它然后重新分配它,但认为这有点浪费资源,但不知道如何清除它以重用它。

4

2 回答 2

22

一种方法是[myString setString: @""].

于 2010-07-26T06:25:15.460 回答
1

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.

于 2012-02-25T08:35:23.197 回答