IPhone GUI for displaying messages in real time

My goal is to have my GUI screen dedicated to logging real-time messages generated by my internal components. A specific limit will be set in the log messages so that old messages are truncated.

I am thinking of using a UITextView with NSMutableString to store output. I would need to do manual trimming in some way on the NSMutableString object. Is this the best way to implement this?

+4
source share
3 answers

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:

+1
source

If you manage your logs into multiple array entries, I suggest implementing it as a table with NSMutableArray.

Array performance is much better than manipulating NSMutableString.

+1
source

I think you need to use the NSFileManager class, take it using the NSFileManager class.

using this class, you can do your job well.

Step:

write the NSLog lines in the NSMutableString, adding the new logs generated at the end of the preveous result line.

and write it to some temp txt file.

and read this file and show the contents of this file in a UITextView.

0
source

Source: https://habr.com/ru/post/1306643/


All Articles