开发者

How to init array in objective-c?

I want to use an array in all 开发者_如何学Cmethods of my class. The array is initialized in the init method of the class.

But the size of the array is first known in the init method. E.g. in my init method I have:

CGPoint mVertices[size][size];

later in init I fill the array and in another method I read the values. How can I declare the array globally?


Make it an ivar:

@interface myClass : NSObject {
  CGPoint *mVertices;
}

@end

In your init method:

mVertices = malloc(size * size * sizeof(CGPoint));
if (!mVertices) { return nil; }

In your dealloc method:

free(mVertices); mVertices = NULL;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜