I want to create an array from a function. The following obviously works, however because my arrays are much larger I want to save the space and the time writing them out.
GLfloat gCubeTextureData_floorj[2] = { 1.0, 1.0 };
In my attempts to create an array from a function, I am getting the error that 'Array initializer must be an initializer list'. However I am initializing the array by returning the list. This is my function call:
GLfloat array[2] = [self createCubeTextureFromX1:0.5f toX2:1.0f toY1:0.0f andY2:0.5f];
I have tried the following for the function:
-(GLfloat[2]) createCubeTextureFromX1:(float)x1 toX2:(float)x2 toY1:(float)y1 andY2:(float)y2 {
GLfloat gCubeTextureData_floorj[2] = { 1.0, 1.0 };
return gCubeTextureData_floorj;
}
and I have tried
-(GLfloat[2]) createCubeTextureFromX1:(float)x1 toX2:(float)x2 toY1:(float)y1 andY2:(float)y2 {
return { 1.0, 1.0 };
}
and both of these don't work. The first gives me the error in the function, the second gives me the error on the function call. Is this possible to do?
In C, arrays are typically returned using pointers.
To do this properly in Objective-C, I'd suggest returning a NSArray from your method.
However, GLFloats aren't native Objective-C objects that can be stored directory in NSArray. To get around this, I'd recommend using NSNumber or NSValue objects to contain your GLfloat values.