ios - How can I find out which run loop a certain NSTimer is on if it was created with scheduledTimerWithTimeInterval? -


if made nstimer scheduledtimerwithtimeinterval, according documentation, should added current run loop. i'd know how check run loop nstimer on.

also, if timer invalidated , new 1 created, how can add new timer same run loop first timer on?

thanks in advance.

i'd know how check run loop nstimer on.

when schedule original timer, can save reference [nsrunloop currentrunloop] know runloop added. can use currentrunloop when inside timer's event handler, too.

but there no simple nstimer method/property use inquire run loop arbitrary nstimer has been scheduled. nor nsrunloop object expose method allow app developer inquire timers have been scheduled on particular run loop.

also, if timer invalidated , new 1 created, how can add new timer same run loop first timer on?

in general, if want schedule nstimer on nsrunloop other current one, rather calling scheduledtimerwithtimeinterval, instantiate timer timerwithtimeinterval , manually add timer particular nsrunloop using run loop's addtimer:mode: method.


all of begs question why you're scheduling timers on run loop other main one. if want use nstimer background thread, have create own run loop on background thread (which little inefficient , not you'd unless had compelling reason).

generally when using nstimer, schedule on main run loop (e.g., schedule main thread) , eliminates need of convoluted logic of creating run loops, keeping track of timer scheduled on run loop, logic associated manually scheduling new timer on same run loop. main run loop quite adequate in gracefully handling multiple timers.

if you're need timers run on thread other main thread, might want consider using gcd dispatch timers, can scheduled on dispatch queue, without needing run loops. (if want schedule more timers same queue previous timer, though, have keep track of queue dispatch timer added.)


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -