Re: Class variable?
Re: Class variable?
- Subject: Re: Class variable?
- From: "Erik D. Holley" <email@hidden>
- Date: Fri, 6 Feb 2004 14:23:16 -0700
Randall,
Objective-C doesn't facilitate class variables. You'll either need to
use a global variable for each class or use a static local variable
somewhere within your class implementation.
Using a globally scoped variable is often more straight forward:
// header file
@interface MyClass : NSObject
{
...
}
- (id)init;
- (id)var;
@end
// source file
id MyClass_classVariable = nil;
@implementation MyClass
- (id)init
{
if(self = [super init]) {
MyClass_classVariable = @"hello";
}
return self;
}
- (id)var
{
return MyClass_classVariable;
}
@end
(You'll need to add deallocation of the MyClass_classVariable at the
appropriate time.)
-Erik
On Feb 6, 2004, at 1:52 PM, Randall Meadows wrote:
[Man, I hope this isn't a stoopit question...]
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?
What I want to do is basically create a class that doles out instances
of a Carbon structure, and include retain/release capability using
reference counting. I was thinking of keeping a NSDictionary of the
structures I create, using the address as the key, and another
NSDictionary for the counts, similarly keyed.
Am I re-inventing the wheel? Am I just too ignorant about Cocoa to
know how to do this with a simple NSObject subclass?
[PS-What are the feelings about cross-posting to cocoa-dev and
macosx-dev? I'm new to both, so I don't have a feel for any "turf
war" that might be going on...]
_______________________________________________
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.
--
Erik D. Holley
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.