Returning a 2D C array from an Objective-C function

前端 未结 2 497
孤独总比滥情好
孤独总比滥情好 2021-01-12 09:17

I want to do achieve something like this in Objective-C

+(int[10][10])returnArray
{
    int array[10][10];
    return array;
}

However, thi

2条回答
  •  攒了一身酷
    2021-01-12 09:49

    Another way you can do it with objective C++, is to declare the array as follows:

    @interface Hills : NSObject
    {
    
    
    @public
        CGPoint hillVertices[kMaxHillVertices];
    }
    

    This means the array is owned by the Hills class instance - ie it will go away when that class does. You can then access from another class as follows:

    _hills->hillVertices 
    

    I prefer the techniques Carl Norum describes, but wanted to present this as an option that might be useful in some cases - for example to pass data into OpenGL from a builder class.

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题