Until you measure and prove that your initial approach is too slow, using too much memory or, otherwise, a problem, I would not be very worried about performance. However, I do not think that I will take Yakub’s proposal and work through the intermediate file.
UITextView sounds ok. First, I would try to collect log messages in NSMutableArray to simplify trimming, and then combine them into one NSString connected by new characters, and assign this to your text view.
At the risk of over-engineering, which can be a debugging tool for development, you might consider moving log management (add, prune, and generate NSString ) to the class. You will have more freedom to change the internal work without thinking about the code that uses it.
@interface LogManager : NSObject { NSMutableArray *messages; } - (void) addMessage:(NSString *)message; - (NSString *) logAsString; @end
The implementation is simple.
Note that you can also make this class aware of your UITextView , but if you do, remember that updates for the user interface must be performed in the main thread (see performSelectorOnMainThread:withObject:waitUntilDone:
source share