StoryboardLoadable

@available(iOS 13.0, *)
public protocol StoryboardLoadable : UIViewController, FlowRepresentable

A protocol indicating this a FlowRepresentable that should be loaded from a storyboard.

Discussion

If you use storyboards in your app and are on iOS 13 or greater StoryboardLoadable provides the best consumer experience for creating your FlowRepresentable.

If you use the convention where the storyboard identifiers are the same name as the UIViewController class you can write an extension so your code makes that assumption.

It may also be a good idea to make your own protocols for each of your storyboards, for the sake of clarity in your code.

Example

extension StoryboardLoadable {
   static var storyboardId: String { String(describing: Self.self) }
}

protocol MainStoryboardLoadable: StoryboardLoadable { }
extension MainStoryboardLoadable {
   static var storyboard: UIStoryboard { UIStoryboard(name: "main", bundle: Bundle.main) }
}
  • Identifier used to retrieve the UIViewController from storyboard.

    Declaration

    Swift

    static var storyboardId: String { get }
  • Storyboard used to retrieve the UIViewController.

    Declaration

    Swift

    static var storyboard: UIStoryboard { get }
  • Creates the specified view controller from the storyboard and initializes it using your custom initialization code.

    Discussion

    This UIKit initializer can be used to pass arguments to the FlowRepresentable. If you return nil, this creates the view controller using the default init(coder:) method.

    Declaration

    Swift

    init?(coder: NSCoder, with args: WorkflowInput)

    Parameters

    coder

    An unarchiver object.

    with

    WorkflowInput data provided by encompassing Workflow; parameter can be renamed.

  • _factory(_:with:) Extension method

    Declaration

    Swift

    public static func _factory<FR>(_: FR.Type, with args: WorkflowInput) -> FR where FR : FlowRepresentable

Available where WorkflowInput == Never