HNDCreatableViewController 0.1.0

HNDCreatableViewController 0.1.0

TestsTested
LangLanguage Obj-CObjective C
License Custom
ReleasedLast Release Sep 2015

Maintained by Dustin Bachrach.



  • By
  • Dustin Bachrach

What is HNDCreatableViewController

We often want to construct View Controllers that we designed in Storyboards. If you want to load these View Controllers, you need to tightly couple your code that creates the View Controller to know which Storyboard hosts the View Controller. Using HNDCreatableViewController, we store that information directly in the View Controller, so that other parts of our application can simply create a View Controller without having to know which Storyboard implements it.

Consider a MyAwesomeViewController, which is designed inside the Awesome.storyboard and has a View Controller Identifier of TotesAwesome.

We define our MyAwesomeViewController to conform to HNDCreatableViewController:

#import <HNDCreatableViewController/HNDCreatableViewController.h>

@interface MyAwesomeViewController : UIViewController <HNDCreatableViewController>

@end

We then implement MyAwesomeViewController and define its Storyboard and View Controller Identifier:

#import <AtSugar/AtSugar.h>
#import <AtSugarMixin/ASMixin.h>

@implementation MyAwesomeViewController

@mixin (MyAwesomeViewController, HNDCreatableViewControllerMixin)

@declare_class_property (viewControllerStoryboard, @"Awesome")
@declare_class_property (viewControllerIdentifier, @"TotesAwesome")

@end

We used AtSugar and AtSugarMixin to make the implementation short and to the point.

That's it. Now if you want to create a MyAwesomeViewController from somewhere else in your code, you can just do:

MyAwesomeViewController* vc = [MyAwesomeViewController create];
[self presentViewController:vc animated:YES completion:nil];

Installation

HNDCreatableViewController is available through CocoaPods. To install it, simply add the following lines to your Podfile. Note: we recommend using AtSugar and AtSugarMixin, so add it to your Podfile as well.

pod "HNDCreatableViewController"
pod "AtSugar"
pod "AtSugarMixin"

Author

Dustin Bachrach, [email protected]

License

HNDCreatableViewController is available under the Apache License 2.0. See the LICENSE file for more info.