Reputation:
I was just wondering if this is possible... if I have a "Static class" (a class with a bunch of static methods) is it possible to have a class variable and access it through one of the static methods?
I am getting a warning of "instance variable accessed in class method". I maybe just not getting it. Is there anyone that can answer this question?
Upvotes: 1
Views: 2567
Reputation: 15511
You can use static variables to implement the equivalent of class variables:
// Foo.h
@interface Foo : NSObject {
}
+ (NSObject*)classVariable;
@end
// Foo.m
#import "Foo.h"
static NSObject* classVariable;
@implementation Foo
+ (NSObject*)classVariable {
return classVariable;
}
@end
Upvotes: 5