Skip to content

Commit 588faef

Browse files
committed
Updates Readme
1 parent 79975d4 commit 588faef

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

README.md

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,41 @@
77
<!-- [![codebeat badge](https://codebeat.co/badges/768d3017-1e65-47e0-b287-afcb8954a1da)](https://codebeat.co/projects/github-com-s4cha-then) -->[![License: MIT](http://img.shields.io/badge/license-MIT-lightgrey.svg?style=flat)](https://github.com/freshOS/then/blob/master/LICENSE)
88
[![Release version](https://img.shields.io/badge/release-0.0.6-blue.svg)]()
99

10-
Decouples routing between ViewControllers
1110

11+
![Router](https://raw.githubusercontent.com/freshOS/Router/master/Infographics.png)
12+
13+
## Why
14+
Because **classic App Navigation** introduces **tight coupling** between ViewControllers.
15+
Complex Apps navigation can look like a **gigantic spider web**.
16+
17+
Besides the fact that **Navigation responsibility is split** among ViewControllers, modifying a ViewController can cascade recompiles and produce **slow compile times.**
18+
19+
## How
20+
By using a Navigation `enum` to navigate we decouple ViewControllers between them. Aka they don't know each other anymore. So modifying `VCA` won't trigger `VCB` to recompile anymore \o/
1221

1322
```swift
14-
// From
15-
navigationController?.pushViewController(AboutViewController(), animated: true)
16-
// to
23+
// navigationController?.pushViewController(AboutViewController(), animated: true)
1724
navigate(.about)
1825
```
1926

20-
- [x] Decouples Viewcontrollers
21-
- [x] Testable navigation
22-
- [x] Faster compile times
23-
24-
A cool side effect of extracting navigation logic on big projects is improving compilation times.
25-
Indeed Strong dependencies due to navigation code often makes Xcode recompile files you never modified. Router enables you to extract your routing logic in a separate file.
27+
Navigation code is now encapsulated in a `AppNavigation` object.
2628

29+
## Benefits
30+
- [x] Decouples ViewControllers
31+
- [x] Makes navigation Testable
32+
- [x] Faster compile times
2733

2834
## Get started
2935

3036
### 1 - Declare your Navigation enum
3137
```swift
3238
enum MyNavigation: Navigation {
3339
case about
40+
case profile(Person)
3441
}
3542
```
43+
Swift enum can take params!
44+
Awesome for us because that's how we will pass data between ViewControllers :)
3645

3746
### 2 - Declare your App Navigation
3847

@@ -44,20 +53,21 @@ struct MyAppNavigation: AppNavigation {
4453
switch navigation {
4554
case .about:
4655
return AboutViewController()
56+
case .profile(let p):
57+
return ProfileViewController(person: p)
4758
}
4859
}
4960
return UIViewController()
5061
}
5162

5263
func navigate(_ navigation: Navigation, from: UIViewController, to: UIViewController) {
53-
if let myNavigation = navigation as? MyNavigation {
54-
switch myNavigation {
55-
case .about:
56-
from.navigationController?.pushViewController(to, animated: true)
57-
}
58-
}
64+
from.navigationController?.pushViewController(to, animated: true)
5965
}
6066
}
67+
68+
A cool thing is that the swift compiler will produce an error if a navigation
69+
case is not handled !
70+
(which would'nt be the case with URL strings for example)
6171
```
6272

6373
### 3 - Register your navigation on App Launch

0 commit comments

Comments
 (0)