How to declare an array of floats as a class variable in Objective-C when the dimension is undefined at the class instantiation time?

前端 未结 3 460
渐次进展
渐次进展 2021-02-11 04:33

In Java, it would look like this:

class Foo
{
  float[] array;
}

Foo instance = new Foo();
instance.array = new float[10];
3条回答
  •  你的背包
    2021-02-11 05:02

    Here's another way to do it. Create a NSMutableArray object and add NSNumber objects to it. It's up to you to decide whether or not this is sensible.

    NSMutableArray *array;
    array = [[NSMutableArray alloc] init];
    [array addObject:[NSNumber numberWithFloat:1.0f]];
    [array release];
    

提交回复
热议问题