Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Singleton.m
#import "SingletonClass.h"
#import "ViewController.h"
@implementation SingletonClass
@synthesize locationManager;
@synthesize startLocation,stopLocation;
@synthesize testStr;
//static SingletonClass *sharedManager = nil;
#pragma mark Singleton Methods
/*+ (SingletonClass *)sharedManager {
static SingletonClass *sharedManager = nil;
if (sharedManager == nil) {
sharedManager = [[super allocWithZone:NULL] init];
}
return sharedManager;
}*/
+(SingletonClass *)sharedManager
{
static SingletonClass *sharedManager = nil;
if (sharedManager !=nil)
{
return sharedManager;
}
static dispatch_once_t pred;
dispatch_once(&pred, ^{
sharedManager = [SingletonClass alloc];
sharedManager=[sharedManager init];
});
return sharedManager;
}
- (id)init
{
self = [super init];
if (self)
{
testStr = [[NSString alloc] initWithString:@"String from Singleton Class, Hello!"];
}
return self;
}
-(void)dealloc
{
// I'm never called!
[locationManager release];
[stopLocation release];
[startLocation release];
[testStr release];
[super dealloc];
}
+ (id)allocWithZone:(NSZone*)zone {
return [[self sharedManager] retain];
}
- (id)copyWithZone:(NSZone *)zone {
return self;
}
- (id)retain {
return self;
}
- (NSUInteger)retainCount {
return NSUIntegerMax;
}
- (oneway void)release {
}
- (id)autorelease {
return self;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.