NSNumber from CGFloat

Guillaume Algis picture Guillaume Algis · Jun 12, 2013 · Viewed 12.9k times · Source

Is there a safe way to "convert" a CGFloat to a NSNumber ?

NSNumber has the numberWithFloat: and numberWithDouble: methods but CGFloat being defined as float or double depending on the platform, it seems risky to use either one of them.

Or is numberWithDouble: safe to use with a CGFloat, as it is the one with the more precision ?

Answer

Lukas Kukacka picture Lukas Kukacka · Jun 12, 2013

I believe @ NSNumber literal is good enough

@(myCGFloat)

Read more here: http://clang.llvm.org/docs/ObjectiveCLiterals.html