views:

38

answers:

1

Let's say I have several lines of code to clarify specific settings on a given UILabel variable:

numberMarkings[selectedBoxX][selectedBoxY][selectedSquareX][selectedSquareY][selectedNoteX][selectedNoteY].text = @"derp";      
numberMarkings[selectedBoxX][selectedBoxY][selectedSquareX][selectedSquareY][selectedNoteX][selectedNoteY].center.x = 5;
numberMarkings[selectedBoxX][selectedBoxY][selectedSquareX][selectedSquareY][selectedNoteX][selectedNoteY].center.y = 3;

I'd like to setup a reference variable (&$varname in PHP) for this massive array index-specified variable in Obj-C. What is the best way to do this?

+2  A: 

Just use a pointer:

UILabel* label = numberMarkings[selectedBoxX][selectedBoxY][selectedSquareX][selectedSquareY][selectedNoteX][selectedNoteY];
label.text = @"derp";
label.center.x = 5;
label.center.y = 3;

Since you are not writing into the array, you don't need anything fancier than that. If you were to overwrite the value in the array, then you could use a pointer to a pointer:

UILabel** label_in_array = &numberMarkings[selectedBoxX]/* ... */[selectedNoteY];
// Write to the label
UILabel* label = *label_in_array;
label.text = @"derp";
// Write to the array
[label release];
*label_in_array = [[UILabel alloc] init]; // Now numberMarkings[][][...][]
                                          // holds a new uilabel object.
Michael Aaron Safyan