How do I make an array of CGFloats in objective c?

旧街凉风 提交于 2019-11-30 11:12:59

You can only add objects to an NSArray, so if you want you add CGFloats to an array, you can use NSNumber.

Eg:

NSNumber * aNumber = [NSNumber numberWithFloat:aFloat];

Then to get it back:

CGFloat aFloat = [aNumber floatValue];

CGFloat i.e. primitive arrays can be constructed like so...

CGFloat colors[] = { 1, 0, 0, 1 };

and subsequently "used" in a fashion similar to...

CGContextSetFillColor(context, colors);

OR (more concisely, via casting)...

CGContextSetFillColor(context, (CGFloat[]){ 1, 0, 0, 1 });

C arrays gross me out... but this CAN be done with "standard ©"!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!