Factory
public protocol Factory : AbstractFactory
The Factory
protocol should be implemented by the instance that produces any types of the view controllers.
NB
Context
represents a payload that you need to pass to your UIViewController
and something that distinguishes it from others.
It is not a View Model or some kind of Presenter. It is the missing piece of information. If your view controller requires a
productID
to display its content, and the productID
is a UUID
, then the type of Context
is the UUID
. The internal logic
belongs to the view controller. Context
answers the questions What to I need to present a ProductViewController and Am I
already presenting a ProductViewController for this product.
-
Type of
UIViewController
thatFactory
can buildDeclaration
Swift
associatedtype ViewController
-
Context
to be passed intoUIViewController
Declaration
Swift
associatedtype Context
-
Builds a
UIViewController
that will be integrated into the stackThrows
TheRoutingError
if build did not succeed.Declaration
Swift
func build(with context: Context) throws -> ViewController
Return Value
The built
UIViewController
instance.
-
prepare(with:
Extension method) Default implementation does nothing
Declaration
Swift
mutating func prepare(with context: Context) throws
-
execute(with:
Extension method) Prepares the
Factory
and builds itsUIViewController
Declaration
Swift
func execute(with context: Context) throws -> ViewController
-
build()
Extension methodBuilds a
Factory
‘s view controller.Declaration
Swift
func build() throws -> ViewController
-
execute()
Extension methodPrepares the
Factory
and builds itsUIViewController
Declaration
Swift
func execute() throws -> ViewController
-
build()
Extension methodBuilds a
Factory
‘s view controller.Declaration
Swift
func build() throws -> ViewController
-
execute()
Extension methodPrepares the
Factory
and builds itsUIViewController
Declaration
Swift
func execute() throws -> ViewController