ShareObject.h
#import@interface ShareObject : NSObject { NSString *someVariable; } @property (nonatomic, retain) NSString *someVariable; + (id)sharedManager; @end
ShareObject.m
#import "ShareObject.h" @implementation ShareObject @synthesize someVariable; + (id)sharedManager { static ShareObject *shareObject = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ shareObject = [[self alloc] init]; }); return shareObject; } - (id)init { if (self = [super init]) { someVariable = @"some value"; } return self; } - (void)dealloc { // Should never be called, but just here for clarity really. } @end
How to use
ShareObject *shareObject = [ShareObject sharedManager];