Reputation: 275
I have a game with a visible running timer, but can only achieve 2 digits of accuracy (#.##) beyond the decimal. Is this a limit of the framework, or is there a workaround? I am trying to achieve 4-6 digits of accuracy (#.######) on this timer.
Upvotes: 0
Views: 125
Reputation: 25318
This is a limitation of the underlying system. iOS is not a realtime system and timers get scheduled on the so called run loop, which dispatches timers once they are due. However, for a timer to get dispatched accurate, the run loop has to run often enough and check the timer on every iteration. The run loop however runs also other stuff, for example the whole event mechanism, messages and networking are run on the run loop, so your timer aren't checked every few nanoseconds (also, the run loop ins't run consistently but gives some time back to the system as well)
Upvotes: 1
Reputation: 8749
A timer on iOS runs at the max frequency of 60Hz so thats why you only get 2 digit accuracy.
You could make a work around by taking the time and the start of your event and then take the time at the end of the event and calculate the difference. This time won't take into account things like frame rate drops, pausing and moving into the background though.
Upvotes: 2