Re: Class variable?
Re: Class variable?
- Subject: Re: Class variable?
- From: John Randolph <email@hidden>
- Date: Fri, 6 Feb 2004 13:39:05 -0800
On Feb 6, 2004, at 12:52 PM, Randall Meadows wrote:
[Man, I hope this isn't a stoopit question...]
The only stupid question is the one you don't ask.
Is there a way in Cocoa to define a class variable that is shared
among all instances of that class, analogous to a +method? How?
Remembering that Objective-C is a superset of C...
The usual way we do this kind of thing in Cocoa programs is to use a
static variable in the .m file, and provide an accessor for it:
static float myClassVar
@implementation MyClass
+ (float) classVarValue { return myClassVar; }
+ (void) setClassVarValue:(float) aValue { myClassVar = aValue; }
@end
..and of course, any method in that file will also be able to see
myClassVar directly.
Other implementations I've seen did things like keep a dictionary of
dictionaries, where the top level dictionary's keys were class names.
[PS-What are the feelings about cross-posting to cocoa-dev and
macosx-dev?
Doesn't bug me much, but I've seen a few complaints.
-jcr
John C. Randolph <email@hidden> (408) 974-8819
Sr. Cocoa Software Engineer,
Apple Worldwide Developer Relations
http://developer.apple.com/cocoa/index.html
_______________________________________________
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.