• 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: Simple newbie problem: Static variables in Objective-C?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Simple newbie problem: Static variables in Objective-C?


  • Subject: Re: Simple newbie problem: Static variables in Objective-C?
  • From: Kurt Revis <email@hidden>
  • Date: Fri, 22 Mar 2002 11:21:59 -0800

On Friday, March 22, 2002, at 10:36 AM, Andrew Baldwin wrote:

I know that it is possible to have static class variables in Objective-C,

Where did you get that idea? It's not possible. However, you can put static variables in the .m file implementing the class, which is usually close enough.

All I want is something like the following:

@interface UniqueIDGenerator : NSObject
{
static unsigned long long msgID;
}
@end

In + (void)initialize I would then set msgID to 0. How do I declare msgID? I can't build because I get "Parse error before static".

Put this in your .m:

static unsigned long long msgID = 0;

and your class and instance methods (and any functions) in the same file can use msgID. There is no need to set the value in +initialize.

--
Kurt Revis
email@hidden
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Simple newbie problem: Static variables in Objective-C? (From: Andrew Baldwin <email@hidden>)

  • Prev by Date: Re: Does NSSound not work in a Unix tool? - SOLUTION
  • Next by Date: NSPoint Documentation
  • Previous by thread: Re: Simple newbie problem: Static variables in Objective-C?
  • Next by thread: Re: Simple newbie problem: Static variables in Objective-C?
  • Index(es):
    • Date
    • Thread