I have a UILabel in an interactive calculator application that is continually being refreshed with a newly formatted message as the user changes a UISlider value. My question is what is the most efficient way to manage the strings:
NSString *data = [[NSString *alloc] initWithFormat:@"Value A: %0.1f, Value B: %0.1f, valueA,valueB];
myUILabel.text = data;
[data release];
or
[myMutableString setString:@""];
[myMutableString appendFormat:@"Value A: %0.1f, Value B: %0.1f, valueA,valueB];
myUILabel.text = myMutableString;
Any advice would be appreciated
Creating a single, non-mutable string (your first example) is going to be more efficient than creating and then modifying a mutable string.
However the real answer is that it doesn’t matter. The amount of time is negligible in user interaction terms, and any temporary objects created as a side effect will be freed on every pass through the event loop anyway, so worrying about this at all is premature optimization.