NEW: Subscribe to Hacking with Swift+ and accelerate your learning! >>

SOLVED: CADisplayLink - how to call a method every 0.5sec?

Forums > Swift

Hi guys,

I stumbled upon CADisplayLink accuracy compared to the Timer, and it seems the better choice when miliseconds in an app are of bigger significance.

I'm looking for a way to solve this seemingly simple issue:

Let's say we have a function:

func printCake() {
print("cake")
}

My question is: how to use the CADisplayLink to call the function every 0.5sec?

Any help will be greatly appreciated, thanks!

   

I dont think you can and should specify this. CADisplayLink is explicitly there to synchronize your drawing code with the display refresh and not arbitrarily use it as a Timer

   

Ah, I see, thank you. Do you suggest I just stick to Timer then?

   

Hacking with Swift is sponsored by Paw

SPONSORED Use Paw to build, test and describe web APIs. Paw has a lightning fast native macOS interface to compose requests, collaborate in real-time on API specs, and generate client code for your applications. You can import and export API definitions.

Discover Paw for Mac

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

Not logged in

Log in
 

Link copied to your pasteboard.