Using iPhone/Objective C CGFloats: Is 0.1 okay, or should it be 0.1f?

前端 未结 1 1155
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-24 07:59

When using an iPhone Objective C method that accepts CGFloats, e.g. [UIColor colorWithRed:green:blue:], is it important to append a f to constant argum

相关标签:
1条回答
  • 2021-01-24 08:17

    It's not important; it won't break anything to use a double-precision constant where a single-precision constant is expected.

    However, if you have turned on the warning about implicit 64-bit-to-32-bit conversions and are building for 32-bit architectures (which I believe includes the iPhone), then you'll want to use single-precision constants simply to avoid getting that warning.

    (Alternatively, you could set that setting to explicitly off, with an architecture condition turning it on for 64-bit architectures. But that currently only matters if you're also using some of your code in a Mac application.)

    0 讨论(0)
提交回复
热议问题