rootstrap / ios-base

Boilerplate for new iOS projects using Swift 5. Provides a handful of functionalities.
https://rootstrap.com/
MIT License
258 stars 63 forks source link

Added Navigators to handle navigation programatically #110

Closed mcousillas6 closed 5 years ago

mcousillas6 commented 5 years ago

Description:

Advantages

Imeplementation details

germanStabile commented 5 years ago

What do you recommend to handle the case when we need to navigate to a certain UIViewController but the view model/params changes?

How about overloading with optional params ?

mcousillas6 commented 5 years ago

Looks great! What do you recommend to handle the case when we need to navigate to a certain UIViewController but the view model/params changes?

To pass parameters, the best approach is to put them as parameters on your Route, if you are using enums like I did you end up with routes like .login(username: String, password: String) then, you can use that to initialize your viewModel & views properly.

mcousillas6 commented 5 years ago

Updated with some improvements:

glm4 commented 5 years ago

Looks great! What do you recommend to handle the case when we need to navigate to a certain UIViewController but the view model/params changes?

To pass parameters, the best approach is to put them as parameters on your Route, if you are using enums like I did you end up with routes like .login(username: String, password: String) then, you can use that to initialize your viewModel & views properly.

Do you thing that creating two different routes for the same view but responding to different view models would be a better approach?

mcousillas6 commented 5 years ago

Looks great! What do you recommend to handle the case when we need to navigate to a certain UIViewController but the view model/params changes?

To pass parameters, the best approach is to put them as parameters on your Route, if you are using enums like I did you end up with routes like .login(username: String, password: String) then, you can use that to initialize your viewModel & views properly.

Do you thing that creating two different routes for the same view but responding to different view models would be a better approach?

Why would you have 2 view models for the same view? šŸ¤” Normally, Views and VMs have a 1 to 1 relation, with the VM defining the business behaviour.

Either way, If you really need different VMs, yes, having two separate routes is better. I would still go for the parameter approach if you only need to inject some property value, for example, if you have a VM that receives an ID to fetch a profile or similar.

glm4 commented 5 years ago

Looks great! What do you recommend to handle the case when we need to navigate to a certain UIViewController but the view model/params changes?

To pass parameters, the best approach is to put them as parameters on your Route, if you are using enums like I did you end up with routes like .login(username: String, password: String) then, you can use that to initialize your viewModel & views properly.

Do you thing that creating two different routes for the same view but responding to different view models would be a better approach?

Why would you have 2 view models for the same view? šŸ¤” Normally, Views and VMs have a 1 to 1 relation, with the VM defining the business behaviour.

Either way, If you really need different VMs, yes, having two separate routes is better. I would still go for the parameter approach if you only need to inject some property value, for example, if you have a VM that receives an ID to fetch a profile or similar.

I meant a view that can be presented in different scenarios using different view models and/or parametes. I think in that case two routes is better to avoid conditionals and extra logic in the same Route case.

mcousillas6 commented 5 years ago

Looks great! What do you recommend to handle the case when we need to navigate to a certain UIViewController but the view model/params changes?

To pass parameters, the best approach is to put them as parameters on your Route, if you are using enums like I did you end up with routes like .login(username: String, password: String) then, you can use that to initialize your viewModel & views properly.

Do you thing that creating two different routes for the same view but responding to different view models would be a better approach?

Why would you have 2 view models for the same view? šŸ¤” Normally, Views and VMs have a 1 to 1 relation, with the VM defining the business behaviour. Either way, If you really need different VMs, yes, having two separate routes is better. I would still go for the parameter approach if you only need to inject some property value, for example, if you have a VM that receives an ID to fetch a profile or similar.

I meant a view that can be presented in different scenarios using different view models and/or parametes. I think in that case two routes is better to avoid conditionals and extra logic in the same Route case.

Oh okay! yes, in that case it's way more clear to have two routes.

CamilaMoscatelli commented 5 years ago

Looks great! :clap: