Skip to content

Commit f060948

Browse files
Update readme to highlight imports (pointfreeco#228)
* Update readme to highlight imports * Correct import minimum required dependency * Correct import minimum required dependency for UIKit example * Update README.md * Update README.md * Update README.md --------- Co-authored-by: Stephen Celis <stephen.celis@gmail.com>
1 parent 54d8d0d commit f060948

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

README.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ SwiftUI, UIKit, AppKit, and even non-Apple platforms.
2929

3030
#### SwiftUI
3131

32-
> [!IMPORTANT]
33-
> To get access to the tools described below you must depend on the SwiftNavigation package and
34-
> import the SwiftUINavigation library.
35-
3632
SwiftUI already comes with incredibly powerful navigation APIs, but there are a few areas lacking
3733
that can be filled. In particular, driving navigation from enum state so that you can have
3834
compile-time guarantees that only one destination can be active at a time.
@@ -96,10 +92,16 @@ This is more concise, and we get compile-time verification that at most one dest
9692
active at a time. However, SwiftUI does not come with the tools to drive navigation from this
9793
model. This is where the SwiftUINavigation tools becomes useful.
9894

95+
> [!IMPORTANT]
96+
> To get access to the tools described below you must depend on the SwiftNavigation package
97+
> (see [Installation](#installation)) and import the **SwiftUINavigation** library.
98+
9999
We start by annotating the `Destination` enum with the `@CasePathable` macro, which allows one to
100100
refer to the cases of an enum with dot-syntax just like one does with structs and properties:
101101

102102
```diff
103+
+import SwiftNavigation
104+
103105
+@CasePathable
104106
enum Destination {
105107
// ...
@@ -110,6 +112,8 @@ And now one can use simple dot-chaining syntax to derive a binding from a partic
110112
the `destination` property:
111113

112114
```swift
115+
import SwiftUINavigation
116+
// ...
113117
.sheet(item: $model.destination.addItem) { addItemModel in
114118
AddItemView(model: addItemModel)
115119
}
@@ -133,7 +137,7 @@ we can still use SwiftUI's navigation APIs.
133137

134138
> [!IMPORTANT]
135139
> To get access to the tools described below you must depend on the SwiftNavigation package and
136-
> import the UIKitNavigation library.
140+
> import the **UIKitNavigation** library.
137141
138142
Unlike SwiftUI, UIKit does not come with state-driven navigation tools. Its navigation tools are
139143
"fire-and-forget", meaning you simply invoke a method to trigger a navigation, but there is
@@ -151,17 +155,20 @@ This makes it easy to get started with navigation, but as SwiftUI has taught us,
151155
powerful to be able to drive navigation from state. It allows you to encapsulate more of your
152156
feature's logic in an isolated and testable domain, and it unlocks deep linking for free since one
153157
just needs to construct a piece of state that represents where you want to navigate to, hand it to
154-
SwiftUI, and let SwiftUI handle the rest.
158+
SwiftUI, and let it handle the rest.
155159

156160
The UIKitNavigation library brings a powerful suite of navigation tools to UIKit that are heavily
157161
inspired by SwiftUI. For example, if you have a feature model like the one discussed above in
158162
the [SwiftUI](#swiftui) section:
159163

160164
```swift
165+
import SwiftNavigation
166+
161167
@Observable
162168
class FeatureModel {
163169
var destination: Destination?
164170

171+
@CasePathable
165172
enum Destination {
166173
case addItem(AddItemModel)
167174
case deleteItemAlert
@@ -173,6 +180,8 @@ class FeatureModel {
173180
…then one can drive navigation in a _view controller_ using tools in the library:
174181

175182
```swift
183+
import UIKitNavigation
184+
176185
class FeatureViewController: UIViewController {
177186
@UIBindable var model: FeatureModel
178187

0 commit comments

Comments
 (0)