Reputation: 111
I want to declare static-class variables in objective-c class and want to use them directly using class name like
E.g
having a class named "Myclassname" and variable "Var"
and want access this variable like this....
Myclassname.Var=@"hi";
I dont want to use getters and setters.
Any help please?
Upvotes: 1
Views: 2062
Reputation: 12421
Variables aren't accessed using the .
syntax - those are getters and setters. Your only option, as @bbarnhart points out, is to manually declare class getters and setters.
@interface Myclassname
+(NSString *)var;
+(void)setVar:(NSString *)newVar;
@end
And implement these methods to access/set the backing static
variable.
This isn't really a good idea, anyway, and doesn't jive with Objective-C style. You should consider using a singleton and properties, instead.
Upvotes: 1
Reputation: 1876
I don't see why you can't use the -> syntax like this:
Myclassname->var = @"Hi";
Upvotes: 0