Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typhoon: Assembly and Storyboard-Created ViewControllers

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?

like image 324
Jasper Blues Avatar asked Sep 25 '13 07:09

Jasper Blues


2 Answers

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.

like image 70
Jasper Blues Avatar answered Nov 20 '22 02:11

Jasper Blues


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.

like image 30
Aleksey Avatar answered Nov 20 '22 03:11

Aleksey