Story Board Manager Generator
StoryBoardManagerGenerator is quite a mouthful. Its a python script for xcode to generate a StoryboardManager class, it parses all storyboard files in a given directory and makes the UIStoryboard* easily accessible and create UIViewController from generated ID's.
It script generates two sets of files:
- _StoryBoardManager.h/.m - AutoGenerated BaseClass with all ID's and basic functionality
- StoryBoardManager.h/.m - Customizable class that is only generated the first time script runs.
StoryBoardManager.h
@interface _StoryBoardManager : NSObject
// Generated for each storyboard file found
+ (UIStoryboard*)main_iphoneStoryBoard;
+ (UIViewController*)viewController:(NSString*)viewControlelrID inStoryBoard:(NSString*)storyboardID;
@end
// StoryBoardIDs
static NSString* StoryBoardID_Main= @"Main";
// Controller ID's
static NSString* SBMainscreen_Main_tabbar = @"main_tabbar";
Naming Convention
These naming conventions are just temporary, open to suggestions if there is anything people prefer or implementing various styles.
StoryBoardID's are just StoryBoardID_{CapitalizedFirstLetter of storyboard filename}
main_iPhone.storyboard = StoryBoardID_Main_iPhone
ControllerID's are the same SB_{CapitalizedFirstLetter storyboardFilename}_{storyboardIdentifier}
main_iPhone.storyboard with controllers storyboardIdentifier "testVC"
ControllerID = SB_Main_iPhone_TestVC
Options
--root or -r is path to recursively search for .storyboard files default is project root
--dest or -d is path to output StoryBoardManager.h/.m and _StoryBoardManager.h/.m default is script directory
Installation
In your App Target add a new runscript
{ Python Directory } { path to generartor script } { options }
Example
/usr/bin/python scripts/StoryboardDefGenerator.py -d "Source"
Alternatively you can add a new build aggregator target and add put in a runscript in that. This allows you to generate the files whenever you want, i.e. after you edit a storyboard.
More Info
Welcome to suggestions, I plan on adding functionality as I need them. I'd like to create a cocoapod to automatically add this functionality to a project but havent gotten around to trying it.