declaring array of an object X with unknown size objective c

前端 未结 2 2106
清酒与你
清酒与你 2021-01-26 07:04

How would I go about declaring an array in the .h file of an unknown size that I will calculate say in the a function inside the class ?

For example, I might have 20 or

2条回答
  •  逝去的感伤
    2021-01-26 07:40

    You have two choices.

    1) Make it an NSArray of NSArrays, or

    2) Declare it as:

    NSArray **arrays_of_unknown_size;
    

    Then you can malloc/calloc the pointer when you know the actual size. Then you need to assign an NSArray to each element of the C-array.

提交回复
热议问题