Define static variable and static method in iPhone and objective C

Posted: October 1, 2011 in iPhone
// MyClass.h
@interface MyClass : NSObject {
+ (NSString*)str;
+ (void)setStr:(NSString*)newStr;

// MyClass.m
#import "MyClass.h"

static NSString* str;

@implementation MyClass

+ (NSString*)str {
    return str;

+ (void)setStr:(NSString*)newStr {
    if (str != newStr) {
        [str release];
        str = [newStr copy];
  1. Woah! I’m really loving the template/theme of this site. It’s simple, yet effective.
    A lot of times it’s difficult to get that “perfect balance” between usability and appearance. I must say you’ve done a amazing job with this.
    Also, the blog loads extremely quick for me on Safari.
    Excellent Blog!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s