来自CGFloat的NSNumber [英] NSNumber from CGFloat

查看:208
本文介绍了来自CGFloat的NSNumber的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种安全的方式来转换 CGFloat NSNumber



NSNumber 包含 numberWithFloat: numberWithDouble:方法,但 CGFloat 被定义为 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆