Throwing an exception when more than 1 instance of SlideNavigationController is being initialized. Can't use dispatch once since SlideNavigationController van be initialized using different constructors

This commit is contained in:
Aryan Ghassemi 2014-04-20 09:16:59 -07:00
parent fd9a508323
commit 3aff93e08e
1 changed files with 11 additions and 2 deletions

View File

@ -57,6 +57,9 @@ static SlideNavigationController *singletonInstance;
+ (SlideNavigationController *)sharedInstance
{
if (!singletonInstance)
NSLog(@"SlideNavigationController has not been initialized. Either place one in your storyboard or initialize one in code");
return singletonInstance;
}
@ -92,13 +95,19 @@ static SlideNavigationController *singletonInstance;
- (void)setup
{
if (singletonInstance)
@throw ([NSException exceptionWithName:@"InvalidInitialization"
reason:@"Singleton instance already exists. You can only instantiate one instance of SlideNavigationController"
userInfo:@{@"instance" : singletonInstance}]);
singletonInstance = self;
self.landscapeSlideOffset = MENU_DEFAULT_SLIDE_OFFSET;
self.portraitSlideOffset = MENU_DEFAULT_SLIDE_OFFSET;
self.avoidSwitchingToSameClassViewController = YES;
singletonInstance = self;
self.delegate = self;
self.enableShadow = YES;
self.enableSwipeGesture = YES;
self.delegate = self;
}
- (void)viewWillLayoutSubviews