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

前端 未结 2 1056
余生分开走
余生分开走 2021-01-01 16:55

So I\'m working on a simple iPhone game and am trying to make a local high score table. I want to make an array and push the highest scores into it. Below is the code I have

相关标签:
2条回答
  • 2021-01-01 17:29

    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];
    
    0 讨论(0)
  • 2021-01-01 17:34

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

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