Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to perform routing in iOS swift modular application?

I am working on a very big app and decided to go with the modular approach where each feature is implemented as a Framework and one feature should not "know" other features.

I decided to use heavily in ReSwift which is a library to build iOS app following the REDUX principles.

I've managed to decouple the global App State from all the Feature state so each feature define its own state and its all managed by the global app state.

The next challenge that I am facing with is Routing / Navigation. I want to be able to route between one view controller which located in Feature1 to another view controller which located in Feature2 (Remember: I want to avoid dependencies between features so Feature1 is not know anything about Feature2).

I know that I can create a central place in my app that can handle all the routes of the application but I wanted to know if there is a way that every Feature will implement its own route. So Feature1 will route to Feature2 without calling to some central implementation. The motivation here is that every Feature will provide its own resources to the app. So in REDUX principles each feature should provide: State, Reducer, Actions and Router but the challenge here is that features is not depended in other feature.

P.S. for routing I decided to go with ReSwift-Router which is a declarative routing library for ReSwift apps.

Thanks!

like image 929
Ran Hassid Avatar asked Nov 05 '18 09:11

Ran Hassid


1 Answers

Looks like we are using a similar architecture pattern, though I decided to define router protocols in each module, all of which are implemented in some central router module. This separates the modules but I'm still able to use a centralized state and dispatch for the whole app.

After playing with some router libraries, I've made my own state-based solution to better handle VCs hierarchy, still separating state from UI.

I think it fits your requirements.

https://github.com/nikans/MonarchRouter

Monarch Router

Monarch Router is a declarative routing handler that decouples ViewControllers from each other via Coordinator and Presenters. It fits right in with Redux style State Flow and Reactive frameworks.

The Coordinator is constructed by declaring a route hierarchy mapped with a URL structure. Presenters abstract UI creation and modification.

Features:

  • Navigating complex ViewControlles hierarchy and unwinding on path change.
  • Deeplinking to handle Push Notifications, Shortcuts and Universal Links.
  • Switching top-level app sections via changing the window's rootViewController.
  • Navigating forks (tab bar like presenters).
  • Navigating stacks (i.e. navigation controller).
  • Opening and dismissing modals, with their own hierarchy.
  • Parsing and passing route parameters to endpoints.
like image 123
nikans Avatar answered Sep 28 '22 16:09

nikans