你不能 - 数组不是C中的左值.你必须声明一个指针属性,并依赖于使用正确数组块的代码,或者使用NSArray属性.
例:
@interface SomeClass
{
int width, height, depth;
int ***array;
}
- (void) initWithWidth:(int)width withHeight:(int)height withDepth:(int)depth;
- (void) dealloc;
@property(nonatomic, readonly) array;
@end
@implementation SomeClass
@synthesize array;
- (void) initWithWidth:(int)width withHeight:(int)height withDepth:(int)depth
{
self->width = width;
self->height = height;
self->depth = depth;
array = malloc(width * sizeof(int **));
for(int i = 0; i < width; i++)
{
array[i] = malloc(height * sizeof(int *));
for(int j = 0; j < height; j++)
array[i][j] = malloc(depth * sizeof(int));
}
}
- (void) dealloc
{
for(int i = 0; i < width; i++)
{
for(int j = 0; j < height; j++)
free(array[i][j]);
free(array[i]);
}
free(array);
}
@end
Run Code Online (Sandbox Code Playgroud)
然后,您可以将该array属性用作三维数组.