From 3aff93e08e09c62a5d52cfd0a23db2dc9911a3aa Mon Sep 17 00:00:00 2001 From: Aryan Ghassemi Date: Sun, 20 Apr 2014 09:16:59 -0700 Subject: [PATCH] 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 --- SlideMenu/Source/SlideNavigationController.m | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/SlideMenu/Source/SlideNavigationController.m b/SlideMenu/Source/SlideNavigationController.m index 86b33ca..c62ec14 100644 --- a/SlideMenu/Source/SlideNavigationController.m +++ b/SlideMenu/Source/SlideNavigationController.m @@ -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