Skip to content

Instantly share code, notes, and snippets.

@Gurdeep0602
Last active October 8, 2018 07:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gurdeep0602/75a23c4eee0479c974427e437eed8309 to your computer and use it in GitHub Desktop.
Save Gurdeep0602/75a23c4eee0479c974427e437eed8309 to your computer and use it in GitHub Desktop.
typedef enum : NSUInteger {
AppStoryboardMain = 0,
AppStoryboardDetail,
} AppStoryboardName;
#define kStoryboardArray @"Main", @"Detail", nil
#define storyboardString(enumVal) [[[NSArray alloc] initWithObjects:kStoryboardArray] objectAtIndex:enumVal]
@interface UIViewController (AppStoryboard)
+ (instancetype)instantiateFromStoryboard:(AppStoryboardName)storyboardName;
@end
@implementation UIViewController (AppStoryboard)
+ (instancetype)instantiateFromStoryboard:(AppStoryboardName)storyboardName {
NSString *storyboardName = storyboardString(storyboard);
// Assume ViewController's storyboardID is identical to ViewController's class name.
NSString *controllerIdentifier = NSStringFromClass([self class]);
return [[UIStoryboard storyboardWithName:storyboardName bundle:nil] instantiateViewControllerWithIdentifier:controllerIdentifier];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment