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 999
执念已碎
执念已碎 2021-02-11 04:36

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:08

    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];
    

提交回复
热议问题