Skip to content

Commit 3aff93e

Browse files
committed
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
1 parent fd9a508 commit 3aff93e

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

SlideMenu/Source/SlideNavigationController.m

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ @implementation SlideNavigationController
5757

5858
+ (SlideNavigationController *)sharedInstance
5959
{
60+
if (!singletonInstance)
61+
NSLog(@"SlideNavigationController has not been initialized. Either place one in your storyboard or initialize one in code");
62+
6063
return singletonInstance;
6164
}
6265

@@ -92,13 +95,19 @@ - (id)initWithRootViewController:(UIViewController *)rootViewController
9295

9396
- (void)setup
9497
{
98+
if (singletonInstance)
99+
@throw ([NSException exceptionWithName:@"InvalidInitialization"
100+
reason:@"Singleton instance already exists. You can only instantiate one instance of SlideNavigationController"
101+
userInfo:@{@"instance" : singletonInstance}]);
102+
103+
singletonInstance = self;
104+
95105
self.landscapeSlideOffset = MENU_DEFAULT_SLIDE_OFFSET;
96106
self.portraitSlideOffset = MENU_DEFAULT_SLIDE_OFFSET;
97107
self.avoidSwitchingToSameClassViewController = YES;
98-
singletonInstance = self;
99-
self.delegate = self;
100108
self.enableShadow = YES;
101109
self.enableSwipeGesture = YES;
110+
self.delegate = self;
102111
}
103112

104113
- (void)viewWillLayoutSubviews

0 commit comments

Comments
 (0)