There are a few extra benefits to a developer who works with SimpleIOSViewStackController and one of them is as a result of observing some best practice and so I will discuss this first.

Best Practice

NSNotification names are NSStrings and as such are a source of many bugs. If you stated that the NSString @"ShowNibViewController" should reveal the NibViewController and you supply @"ShowTheNibViewController" when you post the NSNotification it simply won't work. There will also be no compiler or run time error making this particular bug sometimes quite elusive.

A way of avoiding this pitfall is to define constants to use instead. There are a few ways of going about this but for this tutorial I am going to define them directly in the Precompiled Headers to keep it simple. Find the file that has the same name as your project and an extension of .pch, you can usually find it in the Supporting Files Group and it contains a few imports by default. Add the following :

#define SHOW_STORYBOARD_VIEW_CONTROLLER @"ShowStoryboardViewController"
#define SHOW_NIB_VIEW_CONTROLLER @"ShowNibViewController"
#define SHOW_CLASS_VIEW_CONTROLLER @"ShowClassViewController"

Now find those same NSStrings in the code an replace them with the constants, they should appear in the auto completion suggestion as you type.


- (id) init{
    self = [super init];
    if (self) {
        // storyboard based UIViewController
        self.storyboardName = @"Storyboard";
        SimpleIOSViewStackVO *storyboardViewStackVO = [[SimpleIOSViewStackVO alloc] init];
        storyboardViewStackVO.viewControllerClass = [StoryboardViewController class];
        storyboardViewStackVO.storyboardID = @"StoryboardViewController";
        storyboardViewStackVO.notificationString = SHOW_STORYBOARD_VIEW_CONTROLLER;
        [self registerViewStackVO:storyboardViewStackVO];
        SimpleIOSViewStackVO *nibViewStackVO = [[SimpleIOSViewStackVO alloc] init];
        nibViewStackVO.viewControllerClass = [NibViewController class];
        nibViewStackVO.notificationString = SHOW_NIB_VIEW_CONTROLLER;
        nibViewStackVO.nibName = @"NibViewController";
        [self registerViewStackVO:nibViewStackVO];
        SimpleIOSViewStackVO *classViewStackVO = [[SimpleIOSViewStackVO alloc] init];
        classViewStackVO.viewControllerClass = [ClassViewController class];
        classViewStackVO.notificationString = SHOW_CLASS_VIEW_CONTROLLER;

        [self registerViewStackVO:classViewStackVO];
    return self;

Similarly these are used in the UIButton Action handler methods.


- (IBAction)screenTwoButtonTapped:(id)sender {
    [[NSNotificationCenter defaultCenter]
        postNotificationName: SHOW_NIB_VIEW_CONTROLLER
            object: [[SimpleIOSViewStackNotificationVO alloc]
                        initWithAnimationFlag:YES AndRemoveFlag:NO]];

In addition to avoiding typos and these being included in auto complete I find, as they are a different colour, they stand out a bit more in the code and due to the caps also in search results.

Production Benefits

With one simple search term, a constant, you can find all of the places in your code that bring a particular UIViewController into view.

The second streamlining of the app building production process can be found right where we started. If you change the details of which UIViewController is asked for first, you can jump deep into your application without having to navigate yourself.


- (void)viewDidLoad{
    [super viewDidLoad];
    [[NSNotificationCenter defaultCenter] postNotificationName: SHOW_CLASS_VIEW_CONTROLLER object:nil];


You still need to take care of the Model and aspects of your code that might be sensitive to state but you build robust Models right? The development of many apps could benefit from this approach.

Please feel free to get in touch if you find any of this useful or if you have any other comments.