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: Andy Lee <email@hidden>
- Date: Fri, 22 Mar 2002 14:10:01 -0500
At 1:36 PM -0500 3/22/02, Andrew Baldwin wrote:
I know that it is possible to have static class variables in Objective-C,
Actually, AFAIK you can't. You may be thinking of class variables in
C++ or static members in Java.
All I want is something like the following:
@interface UniqueIDGenerator : NSObject
{
static unsigned long long msgID;
}
@end
You can do this the C way, by declaring a static variable in the .m
file, and adding getter and setter methods if appropriate:
@implementation UniqueIDGenerator
// ...
static unsigned long msgID = 0;
+ (unsigned long)msgID
{
return msgID;
}
+ (void)setMsgID:(unsigned long)newMsgID
{
msgID = newMsgID;
}
// ...
@end
You could also put the static declaration inside a method, if that's
the only method that will access the variable (again, this is just C).
--Andy
_______________________________________________
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.