iphone - What is a runloop? -


after reading documentation nsrunloop did not understand much. spawning secondary thread has nstimer in launch every 1sec. update label on screen performselectoronmainthread..

however work needed runloop not understand concept of it?

anyone try explain it?

thanks.

a run loop effectively:

while(... event ...)     ... handle event ...; 

it runs on thread; main thread has main event loop user events processed , ui drawing, etc, occurs. documentation explains in detail.

however, in case, you don't need thread.

it sounds doing periodically updating label in ui; isn't terribly compute intensive.

just schedule timer in main thread , done it. no need spinning thread, using performselectoronmainthread:, or incurring complexities of guaranteeing data coherency across threads.


sorry -- didn't understand question.

internally, run loop works putting flag in run loop says "after amount of time elapses, fire timer". no additional threads involved and, better yet, isn't polling check time. think of run loop maintaining timeline. it'll passively let time elapse until there of interest found on timeline (all without polling -- polling sucks. avoided.)

it mean, though, timer never 100% accurate. well, if have timer repeating every second, it'll drift on time.

also; instead of directly triggering drawing event. timer should invalidate view needs updating, let underlying objects deal when best update screen.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -