开发者

Is there any reason to use Core Graphics data types when working with UIView objects

Is there any real need to do this:

CGFloat x = 10.0f;
CGFloat y开发者_StackOverflow中文版 = 20.0f;

someView.center = CGPointMake(x, y);

Instead of this:

float x = 10.0;
float y = 20.0;

someView.center = CGPointMake(x, y);

...aside from style considerations?

Are there any performance implications at all?


Usually those sorts of data types are used for readability, but also for portability. If the CoreGraphics library were to change it's implementation or data types the CGFloat type would help it better match the API. This can also be significant when considering portability across platforms.

I doubt there is any sort of performance difference - it will probably end up still being a float in the compiled code.


See this answer for a good explanation of CGFloat. It is basically a typedef for code portability between 32-bit and 64-bit platforms.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜