来自CGFloat的NSNumber [英] NSNumber from CGFloat
本文介绍了来自CGFloat的NSNumber的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
CGFloat
为 NSNumber
? NSNumber
包含 numberWithFloat:
和 numberWithDouble:
方法,但 float
或 double
取决于平台,使用其中任何一个似乎都有风险。
或者 numberWithDouble:
安全地使用 CGFloat
,因为它是更精确的?
解决方案我相信
@
NSNumber
文字就足够了 @(myCGFloat)
: http://clang.llvm.org/docs/ObjectiveCLiterals.html
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 ?
解决方案
I believe @
NSNumber
literal is good enough
@(myCGFloat)
Read more here: http://clang.llvm.org/docs/ObjectiveCLiterals.html
这篇关于来自CGFloat的NSNumber的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文