This is what I'd do. It assumes that the array is only directly referenced from that class method. If not, it can be moved back outside the method body. Also, unless you have reason to expect a negative index, it doesn't make sense to type it as [signed] int. And if the rectangles are supposed to be constant, change both the return type and the type of the array to const CGRect.
+ (CGRect*) verticalRect:(unsigned int)index { static CGRect sNutVerRect[] = { {{ 69, 118}, {94, 94}}, {{156, 1188}, {94, 94}}, {{ 26, 1948}, {94, 94}}, {{113, 1948}, {94, 94}}, {{200, 1948}, {94, 94}}, {{ 69, 2708}, {94, 94}}, {{156, 2708}, {94, 94}} };
return (index < sizeof(sNutVerRect) / sizeof(sNutVerRect[0])) ? &sNutVerRect[index] : nil; }
On Jul 31, 2009, at 5:46 PM, Agha Khan wrote: I know it is wrong but looking the right way to do it. I would like to save it so I could call it from anywhere.
You help will be very much appreciated.
static CGRect nutVerRect[7];
+ (CGRect*) VerticalRect:(int) Index { if (Index < 0 || Index > 6) return nil; nutVerRect[0] = CGRectMake(69,118,94,94); nutVerRect[1] = CGRectMake(156,118,94,94); nutVerRect[2] = CGRectMake(26,194,94,94); nutVerRect[3] = CGRectMake(113,194,94,94); nutVerRect[4] = CGRectMake(200,194,94,94); nutVerRect[5] = CGRectMake(69,270,94,94); nutVerRect[6] = CGRectMake(156,270,94,94);
return &nutVerRect[Index]; }
|