tags:

views:

576

answers:

3

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

+3  A: 

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.

Dave DeLong
+1  A: 

Here's another way:

NSString *const someString = @"TheStringHere";

iPhoneDevTips

John
A: 

This'll do it ;-)

- (void)foo {
    static NSString *bar = @"My String";
}
Michael Waterfall