how to declare static NSString ,if i declare within the interface as static NSString *str; and i set to property as @property (nonatomic, retain) static NSString *sportsName;
it gives error?any tutorial
how to declare static NSString ,if i declare within the interface as static NSString *str; and i set to property as @property (nonatomic, retain) static NSString *sportsName;
it gives error?any tutorial
If by static you mean it operates on the class and not the instance of the class, you do it like this:
//In the header file:
+ (NSString *)myStaticString;
//In the implementation file:
+ (NSString *)myStaticString { return @"Hello world!"; }
If by static you mean global, then just declare it outside the scope of a class.
@property
declarations are only for instance (non-class) methods. They cannot be used to declare accessors for a static variable.
This'll do it ;-)
- (void)foo {
static NSString *bar = @"My String";
}