Is there a constant for the maximum CGFloat value?

For those using Swift 2, you should use:

CGFloat.max

For those using Swift 3, you should use:

CGFloat.greatestFiniteMagnitude

Note that CGFloat.max was removed when Swift 3 came out, as reflected in the documentation.


CGGeometry defines:

#define CGFLOAT_MAX FLT_MAX

How about CGFLOAT_MAX?


I was looking for a Swift version of minimum CGFloat value and landed here, if you too ;) then here is the answer:

CGFloat.leastNormalMagnitude

A CGFloat is just a float so you can safely use FLT_MAX from <float.h>.

EDIT: As others have now pointed out it looks like CGFLOAT_MAX is already defined for you so you should use that for consistency rather than FLT_MAX, even though they are the same thing on 32 bit platforms.