• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: static Objects
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: static Objects


  • Subject: Re: static Objects
  • From: Steve Christensen <email@hidden>
  • Date: Fri, 31 Jul 2009 17:56:47 -0700

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];
}

Attachment: PGP.sig
Description: PGP signature

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >static Objects (From: Agha Khan <email@hidden>)

  • Prev by Date: static Objects
  • Previous by thread: static Objects
  • Index(es):
    • Date
    • Thread