Last active
October 8, 2018 07:23
-
-
Save Gurdeep0602/75a23c4eee0479c974427e437eed8309 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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