10

I have an ivar which is alloc-inited in the init of an object:

attString = [[NSMutableAttributedString alloc] init];

On a loop, I want to clear the contents of attString and re-use it. How do I do this?

Thanks!

jowie
  • 8,028
  • 8
  • 55
  • 94

3 Answers3

17
[[attString mutableString] setString:@""];
kennytm
  • 510,854
  • 105
  • 1,084
  • 1,005
2
[attString release];
attString = [[NSMutableAttributedString alloc] init];

Kenny's method probably quicker.

Alastair Stuart
  • 4,165
  • 3
  • 36
  • 33
0

I didn't find out the methods that @kennytm mentioned above, but I did it with this:

[attriString setAttributedString:[NSAttributedString new]];

Available from mac10.0 and ios3.2 or later. Good luck for new searchers!

Itachi
  • 5,777
  • 2
  • 37
  • 69