Re: Simple newbie problem: Static variables in Objective-C?
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.