Skip to content

Conversation

@Savva-Shuliatev
Copy link
Contributor

Add BuildFactory to assemble steps with a build closure (no custom Factory type required)

Summary
This PR introduces BuildFactory, a lightweight Factory implementation that lets you provide a factory via a build closure directly in StepAssembler. This removes the need to create a separate Factory type when you only need to construct a UIViewController from its Context if needed.

Motivation
Reduce boilerplate: no need to define a dedicated Factory type for simple constructors.
Improve readability: the creation logic lives next to the step configuration.
Stay fully type-safe: generics keep ViewController and Context strongly typed.

What’s included

  • BuildFactory<viewcontroller, context> that conforms to Factory.
  • A shorthand static constructor BuildFactory.build(...) for concise usage in StepAssembler chains.
  • A StepAssemblerWithFinder extension to accept BuildFactory via .factory(.build { ... }).

Usage example
Below is a minimal example that builds ProductViewController with a String context and assembles a step using .factory(.build { ... }):

class ProductViewController: UIViewController {

    let context: String

    init(context: String) {
        self.context = context
        super.init(nibName: nil, bundle: nil)
    }

    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}

@MainActor
var productScreen: DestinationStep<ProductViewController, String> {
    StepAssembler<ProductViewController, String>()
        .finder(.classFinder)
        .factory(.build { ProductViewController(context: $0) })
        .using(.replaceRoot)
        .from(.root)
        .assemble()
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant