Routable

public protocol Routable : AnyObject

A protocol that all navigable ViewControllers should adhere to. The UINavigationController and the UITabBarController should NOT adhere to this protocol.

  • The identifier associated to the routable element.

       extension ProfileViewController: Routable {
    
         var screenIdentifier: ScreenIdentifier {
           "profile"
         }
       }
    

    Declaration

    Swift

    static var screenIdentifier: ScreenIdentifier { get }
  • assign(model:) Default implementation

    Due to limitations with generics, and the inability to leverage Type Erasure in this specific case, It is impossible to automatically cast an extracted RoutableViewController to its right type, preventing the automatic assignment of the passed viewmodel to the view controller. To work around it, assign(model: Any) -> Bool is introduced and should be used as follow:

    func assign(model: Any) -> Bool {
      guard let model = model as? DemoViewModel else {
        return false
      }
      self.viewModel = model
      return true
    }
    

    Default Implementation

    Declaration

    Swift

    @discardableResult
    func assign(model: Any) -> Bool