• 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: NSArray as a static
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSArray as a static


  • Subject: Re: NSArray as a static
  • From: "Clark Cox" <email@hidden>
  • Date: Tue, 2 Sep 2008 09:51:34 -0700

On Tue, Sep 2, 2008 at 8:45 AM, Richard Good <email@hidden> wrote:
> It appears that the line
>>
>>   static NSArray* constants = nil;
>
> is only being executed on the first call to the method and being ignored on
> all subsequent calls.
> Could someone please explain why?  Thanks.

That's the point of "static". The variable "constants" is essentially
a global variable that is only visible from within the
"myListOfStringConstants" method. Like any other global variable, it
is initialized at the beginning of the program's execution, and lives
until the program exits.

> On Sep 1, 2008, at 5:28 PM, Graham Cox wrote:
>
>> for example:
>>
>>
>> + (NSArray*)                    myListOfStringConstants
>> {
>>   static NSArray* constants = nil;
>>
>>   if( constants == nil )
>>       constants = [[NSArray arrayWithObjects:@"constant1", @"constant2",
>> @"constant3", nil] retain];
>>
>>   return constants;
>> }

--
Clark S. Cox III
email@hidden
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >NSArray as a static (From: Richard Good <email@hidden>)
 >Re: NSArray as a static (From: "Kyle Sluder" <email@hidden>)
 >Re: NSArray as a static (From: Richard Good <email@hidden>)
 >Re: NSArray as a static (From: Graham Cox <email@hidden>)
 >Re: NSArray as a static (From: Richard Good <email@hidden>)

  • Prev by Date: converting from decimal to hexadecimal
  • Next by Date: Re: converting from decimal to hexadecimal
  • Previous by thread: Re: NSArray as a static
  • Next by thread: Re: NSArray as a static
  • Index(es):
    • Date
    • Thread