Objective-C Singleton

Header file (MySingleton.h)

#import <UIKit/UIKit.h>
 
@interface MySingleton : NSObject  {
}
 
@end

Implementation File (MySingleton.m)

#import "MYSingleton.h"
 
@implementation Mysingleton
    static Idea *_instance = NULL;
 
+ (MySignleton *) getInstance {
    @synchronized(self) {
        if (NULL == _instance)
            _instance = [[self alloc] init];
    }
 
    return _instance;
}

Nice, plain and simple. But i’m always open for suggestions.

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>