how to repeat animation forever in Swift (HUGE_VALF)? how to repeat animation forever in Swift (HUGE_VALF)? swift swift

how to repeat animation forever in Swift (HUGE_VALF)?


Set the repeatCount to Float.infinity. This compiles and works.

In all probability, HUGE_VALF was a legacy value in any case.

Still, it's a bit of a surprise that these numeric constant names are not seen by Swift. I did try importing <stdlib.h> in the bridging header but it didn't help.


But please see now Martin R's answer. Since the time when I posted my answer, Apple has stated their preferred answer explicitly: use .greatestFiniteMagnitude. It is almost the same thing as .infinity but not quite!


The current documentation for the repeatCount property of CAMediaTiming states:

Setting this property to greatestFiniteMagnitude will cause the animation to repeat forever.

And that compiles without problems:

let ba = CABasicAnimation()ba.repeatCount = .greatestFiniteMagnitude

The reason that HUGE_VALF is not imported into Swift is thatit is defined as a "non-trivial" macro in <math.h>:

#   define    HUGE_VALF    __builtin_huge_valf()


I use the "HUGE" value. it is a build_in readonly var;