Created
December 11, 2018 09:25
-
-
Save Oni-zerone/bc62afa8d2e7aa6c6996a3116f71504e to your computer and use it in GitHub Desktop.
AbstractFactory from PowerTools
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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