Skip to content

Instantly share code, notes, and snippets.

@rcdilorenzo
Last active December 25, 2015 07:49
Show Gist options
  • Save rcdilorenzo/6942398 to your computer and use it in GitHub Desktop.
Save rcdilorenzo/6942398 to your computer and use it in GitHub Desktop.
Get the main storyboard in an iOS app as set by the .plist file. (You may need to change the return type to id if you are on 6.1 or earlier.)
#import <UIKit/UIKit.h>
@interface UIStoryboard (LDMain)
+ (instancetype)mainStoryboard;
@end
#import "UIStoryboard+LDMain.h"
UIStoryboard *_mainStoryboard = nil;
@implementation UIStoryboard (LDMain)
+ (instancetype)mainStoryboard {
if (!_mainStoryboard) {
NSBundle *bundle = [NSBundle mainBundle];
NSString *storyboardName = [bundle objectForInfoDictionaryKey:@"UIMainStoryboardFile"];
_mainStoryboard = [UIStoryboard storyboardWithName:storyboardName bundle:bundle];
}
return _mainStoryboard;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment