My intent with this code is mainly to help teach someone how to go about this without a separate writeup explaining the code; it's meant to accompany the explanation of the in my answer.With that in mind, I put in a ton of comments attempting to explain what I'm doing and why I'm doing it, even when it seemed obvious. Since this is written in Swift and the language is new, there are also some comments explaining some things that need to be considered for Swift specifically. var data: UInt64 = 0 var ui Update Count: UInt64 = 0 var ui Update Timer: NSTimer? Feel free to play with this value and see what happens, even 0.01 (~1/60th of a second) only uses ~4% CPU for the UI thread on my machine.The more correct way to handle this sort of stuff, in my opinion, isn't to have a looping updater that refreshes your entire UI every 10ms (consider a more complicated view with several more elements to update).
If the text field contains text, the text displays in the label as it should.
If I place the line of code above just before the code that reads and outputs the text field, then instead of the text box showing that text box, the text box text just disappears as if I had over written the contents of the field with an empty string. Suggestionsn would be welcome; the almost identical expression I am using on the label works fine:[_lbl Out Put set String Value:_txt IP]; So I have no idea what I am doing wrong... Dave cocoa edited Aug 4 '11 at Joshua Nozzi 52.2k 12 114 117 asked Aug 4 '11 at user867358 52 8 Show us "the code that reads and outputs the text field".
The appropriate approach then can only logically be to dispatch the UI update onto the main thread from the background thread when new data has actually been received.
Welcome to Mac Help where discuss anything Apple related or seek expert tech support.
The text field is set to wrap in Interface Builder.
What is a simple and reliable way to do this cocoa nstextfield autolayout | this question asked May 5 '12 at Monolo 15.7k 9 51 89 add a comm | up vote 0 down vote For text input, are you using a NSText Field or an NSText View?I think people who need a tutorial instead of just reading documentation are more likely going to want something that looks comfortable and familiar. I don't like the idea that someone would be taught that there should be no synchronization between data updates and UI updates. And you're right, even updating at 10 milliseconds, you don't use that much processing power.Yes, your code does manage to update the UI on the main thread, and it does manage to update the data in the background thread. But any time you update the UI when the data hasn't updated, you've wasted time on the processor.They are vastly different in handling, set String Value: works for NSText Field, yet NSText View requires an attributed string to be passed to [[text View text Storage] set Attributed String:...].answered Aug 4 '11 at Fabian 1,044 6 14 I am definitely using a Text Field.I thought it would be helpful to put together an example of what I'm talking about in the second part of my answer to this Stack Overflow question.