What is the best way to trigger a function/block at a precise (within 1 second) date/time in Swift on iOS?
I’ve tried using Timer’s init with fireAt, but I’m finding that the precision is often off by a few seconds. Setting Timer precision to a value like 0.5 has not yielded better results.
I’ve also tried using GCD with DispatchQueue.main.asyncAfter(.now() + someDelay) and that is also often off by a few seconds in my testing.
What I’ve settled on is creating a Timer that fires once per second and then I’m checking if the current date/time has elapsed my desired value and then I manually trigger my code. It seems like there might be a better way to go about this, but I’m out of ideas. Thanks!