Skip to content

Instantly share code, notes, and snippets.

@Oni-zerone
Created December 11, 2018 09:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Oni-zerone/bc62afa8d2e7aa6c6996a3116f71504e to your computer and use it in GitHub Desktop.
Save Oni-zerone/bc62afa8d2e7aa6c6996a3116f71504e to your computer and use it in GitHub Desktop.
AbstractFactory from PowerTools
public protocol AbstractFactory {
associatedtype Context
var context: Context { get }
var presenterViewController: UIViewController? { get }
func make(from builder: Builder<Context>) -> UIViewController?
func getBuilder(from builderContainer: BuilderContainer) -> Builder<Context>?
}
public extension AbstractFactory {
func getBuilder(from container: BuilderContainer) -> Builder<Context>? {
return container.getBuilder(Context.self)
}
func make(from builder: Builder<Context>) -> UIViewController? {
return builder.build(self.context)
}
}
public extension AbstractFactory where Self: UIViewController {
var presenterViewController: UIViewController? {
return self
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment