So i just switched from xcode 4.2 to 4.3 and now my old way of creating/using singletons doesnt work. So i did my research on how to set up a singleton and i have this code here.
GlobalLogin.h
@interface GlobalLogin : UIViewController
+(GlobalLogin *)sharedInstance;
@end
GlobalLogin.m
@implementation GlobalLogin
#pragma mark -
#pragma mark Singleton Methods
+ (GlobalLogin*)sharedInstance {
static GlobalLogin * sharedInstance;
if(!sharedInstance) {
static dispatch_once_t oncePredicate;
dispatch_once(&oncePredicate, ^{
sharedInstance = [[super allocWithZone:nil] init];
});
}
return sharedInstance;
}
+ (id)allocWithZone:(NSZone *)zone {
return [self sharedInstance];
}
- (id)copyWithZone:(NSZone *)zone {
return self;
}
#if (!__has_feature(objc_arc))
- (id)retain {
return self;
}
- (unsigned)retainCount {
return UINT_MAX; //denotes an object that cannot be released
}
- (void)release {
//do nothing
}
- (id)autorelease {
return self;
}
#endif
#pragma mark -
#pragma mark Custom Methods
So i have all that okay, but my problem is i cant find anywhere how to access its information in the various view controllers that need to use it. So if someone could point me in the right direction that’d be much appreciated.
I have no idea why you would call
+[super alloc], which should already basically be called by alloc itself, but I think you meant-[super init], which even in itself should already by called by-init. Change your initializer to readThen override
-initand call super: