Skip to content

Commit

Permalink
Merge pull request #770 from 417-72KI/native-di-with-storyboard
Browse files Browse the repository at this point in the history
Support dependency injection with storyboards
  • Loading branch information
tomlokhorst committed Nov 30, 2022
2 parents c883f8d + 086aefa commit 691a53e
Showing 1 changed file with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,22 @@ extension StoryboardReference where Self: InitialControllerContainer {
}
}

extension StoryboardReference where Self: InitialControllerContainer, InitialController: UIViewController {
/**
Instantiates and returns the initial view controller in the view controller graph with native dependency injection.
- parameter creator: The function to inject dependency.
- returns: The initial view controller in the storyboard.
*/
@available(iOS 13.0, tvOS 13.0, *)
public func instantiateInitialViewController(
_ creator: @escaping (NSCoder) -> InitialController?
) -> InitialController? {
UIStoryboard(name: name, bundle: bundle)
.instantiateInitialViewController(creator: creator)
}
}

extension StoryboardViewControllerIdentifier {
/**
Expand All @@ -35,6 +51,22 @@ extension StoryboardViewControllerIdentifier {
}
}

extension StoryboardViewControllerIdentifier where ViewController: UIViewController {
/**
Instantiates and returns the view controller with the specified resource (`R.storyboard.*.*`) and native dependency injection.
- parameter creator: The function to inject dependency.
- returns: The view controller corresponding to the specified resource (`R.storyboard.*.*`).
*/
@available(iOS 13.0, tvOS 13.0, *)
public func callAsFunction(
_ creator: @escaping (NSCoder) -> ViewController?
) -> ViewController? where ViewController: UIViewController {
UIStoryboard(name: storyboard, bundle: bundle)
.instantiateViewController(identifier: identifier, creator: creator)
}
}

extension UIStoryboard {
/**
Expand Down

0 comments on commit 691a53e

Please sign in to comment.