Skip to content

Instantly share code, notes, and snippets.

@besi
Forked from rpak/Environment.m
Created January 23, 2012 12:08
Show Gist options
  • Save besi/1662768 to your computer and use it in GitHub Desktop.
Save besi/1662768 to your computer and use it in GitHub Desktop.
Sample code for a Singleton that provides configuration or environment data
#import "Environment.h"
@implementation Environment
static Environment *sharedInstance = nil;
@synthesize myApiURL;
- (id)init
{
self = [super init];
if (self) {
// Do Nada
}
return self;
}
- (void)initializeSharedInstance
{
NSString* configuration = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"Configuration"];
NSBundle* bundle = [NSBundle mainBundle];
NSString* envsPListPath = [bundle pathForResource:@
"Environments" ofType:@"plist"];
NSDictionary* environments = [[NSDictionary alloc] initWithContentsOfFile:envsPListPath];
NSDictionary* environment = [environments objectForKey:configuration];
self.myAPIURL = [environment valueForKey:@"myAPIURL"];
[environments release];
}
#pragma mark - Lifecycle Methods
+ (Environment *)sharedInstance
{
@synchronized(self) {
if (sharedInstance == nil) {
sharedInstance = [[self alloc] init];
[sharedInstance initializeSharedInstance];
}
return sharedInstance;
}
}
- (NSUInteger) retainCount
{
return NSUIntegerMax;
}
- (void) release
{
// Do Nada
}
- (id) autorelease
{
return self;
}
- (id) retain
{
return self;
}
- (void) dealloc
{
[super dealloc];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment