Typhoon: Assembly and Storyboard-Created ViewControllers
Asked Answered
W

2

8

How would I use Typhoon with iOS storyboards where view controllers are generated implicitly by the system? Would I have to do something special in the prepareForSegue methods?

Washington answered 25/9, 2013 at 7:28 Comment(0)
V
7

It is very simple with TyphoonStoryboard

By bootstrapping Typhoon in your plist, along with the usual UILaunchStoryboardName and UIMainStoryboardFile, Typhoon will ensure that all Storyboards are an instance of TyphoonStoryboard. Use exactly as you would a normal Storyboard, with the added benefit that dependencies will be injected according to the definitions in your TyphoonAssembly class(es).

Optionally, you can specify which definition should be used for each viewController. For that, use 'typhoonKey' runtime attribute in storyboard. Otherwise the definition matching the controller class will be used. Example:

example

The documentation for this feature is here.

Varien answered 21/4, 2014 at 20:5 Comment(0)
W
8

There is a TyphoonStoryBoard component in the backlog, however it hasn't been implemented yet (see update below).

There is currently a -injectProperties: method on the component factory that you can use to apply dependency injection on a component after it has been instantiated, ex. by the story board.

For now, you could subclass UIStoryboard and call the -injectProperties: on the view controller by overriding:

– instantiateInitialViewController
– instantiateViewControllerWithIdentifier:

Example:

- (id)instantiateViewControllerWithIdentifier:(NSString *)identifier {
  id instantiatedViewController = [super instantiateViewControllerWithIdentifier:identifier];
  [[TyphoonComponentFactory defaultFactory] injectProperties:instantiatedViewController];
  return instantiatedViewController;
}

Update:

TyphoonStoryBoard integration has now been completed (pending documentation), and committed to master. It will be released as part of Typhoon 2.0, in the coming weeks.

Washington answered 25/9, 2013 at 7:30 Comment(4)
Sounds awesome. Will Typhoon make storyboard-based view controllers much more testable? It's been a pain thinking about TDD with them.Levo
@Levo Yes, all the regular benefits of DI: Easy testing, easy maintenance, good cohesion, etc.Washington
Ahkay. If I may make a suggestion, and that is, the framework needs a LOT more examples in the user guide. Storyboards for example are confusing, because in actual code, the runtime decides what VC's to load, and effectively manages view controller dependencies for you. It's not clear how Typhoon intercepts this process, if at all. I've seen that you need a TyphoonFactory or some such, but does it have an awareness of segues that are happening?Levo
There will be documentation for this Typhoon 2.0 feature when it is released. With the release of Typhoon 2.0, we'll be focusing on providing better documentation, tutorials, blogs, etc. . . (there may even be a book). . meantime, please feel free raise issues, ask on StackOverflow, etc. . thanks for being a Typhoon early adopter!Washington
V
7

It is very simple with TyphoonStoryboard

By bootstrapping Typhoon in your plist, along with the usual UILaunchStoryboardName and UIMainStoryboardFile, Typhoon will ensure that all Storyboards are an instance of TyphoonStoryboard. Use exactly as you would a normal Storyboard, with the added benefit that dependencies will be injected according to the definitions in your TyphoonAssembly class(es).

Optionally, you can specify which definition should be used for each viewController. For that, use 'typhoonKey' runtime attribute in storyboard. Otherwise the definition matching the controller class will be used. Example:

example

The documentation for this feature is here.

Varien answered 21/4, 2014 at 20:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.