I am using [NSTimer scheduledTimerWithInterval:selector:@selector(loop):repeats:YES]
to create a neverending loop with -loop()
being called every interval. My viewcontroller also 开发者_开发百科has a -touchesBegan
to process UITouch's.
Suppose the screen is touched and a UIEvent is fired, does the code in -touchesBegan
execute first in the run loop or the code in the -loop
called by NSTimer execute first?
It's explained in this Apple document.
However, it's not that useful. NSTimer
is not a real-time mechanism, and you can't predict exactly when it fires. It will also depend how often iOS registers touch events, and how often you configure the timer to fire. It would be a very, very, very bad idea to write a code which depends on these subtleties and features buried deep in the documentation I just cited.
Write code which doesn't depend on what you just asked.
精彩评论