Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>A run loop is effectively:</p> <pre><code>while(... get an event ...) ... handle event ...; </code></pre> <p>It runs on a thread; the main thread has the main event loop where user events are processed and most UI drawing, etc, occurs. The <a href="http://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSRunLoop_Class/Reference/Reference.html" rel="noreferrer">documentation explains it in detail</a>.</p> <p>However, in your case, <strong>you don't need a thread</strong>.</p> <p>It sounds like all you are doing is periodically updating a label in the UI; something that isn't terribly compute intensive.</p> <p>Just schedule your timer in the main thread and be done with it. No need for spinning up a thread, using <code>performSelectorOnMainThread:</code>, or incurring all the complexities of guaranteeing data coherency across threads.</p> <hr/> <p>Sorry -- didn't understand your question.</p> <p>Internally, a run loop works by basically putting a flag in the run loop that says "after this amount of time elapses, fire the timer". No additional threads involved and, better yet, it isn't polling to check the time. Think of a run loop as effectively maintaining a timeline. It'll passively let time elapse until there is something of interest found on the timeline (all without polling -- polling sucks. to be avoided.)</p> <p>It does mean, though, that a Timer will never be 100% accurate. As well, if you have a timer repeating every second, it'll drift over time.</p> <p>Also; instead of directly triggering a drawing event. Your timer should invalidate the view that needs updating, then let the underlying objects deal with when it is best to actually update the screen. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload