开发者

order of execution in run loop

开发者 https://www.devze.com 2023-01-29 14:39 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消