AnyScreen

public struct AnyScreen<Container> : Screen where Container : ScreenContainer

A screen that performs type erasure by wrapping another screen.

AnyScreen is a concrete implementation of Screen that has no significant properties of its own, and passes through elements from its wrapped screen.

Use AnyScreen to wrap a screen whose type has details you don’t want to expose across API boundaries, such as different modules. When you use type erasure this way, you can change the underlying screen implementation over time without affecting existing clients.

To make the constructions as compact as possible, you can use aliases for AnyScreen with a specific type of its container:

typealias AnyModalScreen = AnyScreen<UIViewController>
typealias AnyStackScreen = AnyScreen<UINavigationController>
typealias AnyTabsScreen = AnyScreen<UITabBarController>

You can use eraseToAnyScreen() method to wrap a screen with AnyScreen:

func chatScreen(chatID: Int) -> AnyModalScreen {
    ChatScreen(chatID: chatID).eraseToAnyScreen()
}

See also

Screen
  • Declaration

    Swift

    public var name: String { get }
  • Declaration

    Swift

    public var traits: Set<AnyHashable> { get }
  • Declaration

    Swift

    public var description: String { get }
  • Creates a type-erasing screen to wrap the provided screen.

    Declaration

    Swift

    public init<Wrapped: Screen>(
        _ wrapped: Wrapped
    ) where Wrapped.Container == Container

    Parameters

    wrapped

    A screen to wrap with a type-eraser.

  • Declaration

    Swift

    public func build(navigator: ScreenNavigator) -> Container