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

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


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 ©"!