Typhoon: Assembly and Storyboard-Created ViewContr

2019-02-16 19:40发布

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?

2条回答
We Are One
2楼-- · 2019-02-16 19:51

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.

查看更多
看我几分像从前
3楼-- · 2019-02-16 19:55

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.

查看更多
登录 后发表回答