Skip to content

Commit faff23b

Browse files
committed
Update README for checkpoints
1 parent eb6f591 commit faff23b

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

README.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,15 @@ Fortunately, Navigator supports checkpoints; named points in the navigation stac
155155

156156
Checkpoints are easy to define and use. Let's create one called "home" and then use it.
157157
```swift
158-
extension NavigationCheckpoint {
159-
public static let home: NavigationCheckpoint = "home"
158+
struct KnownCheckpoints: NavigationCheckpoints {
159+
public static var home: NavigationCheckpoint { checkpoint() }
160160
}
161161

162162
struct RootHomeView: View {
163163
var body: some View {
164164
ManagedNavigationStack(scene: "home") {
165165
HomeContentView(title: "Home Navigation")
166-
.navigationCheckpoint(.home)
166+
.navigationCheckpoint(KnownCheckpoints.home)
167167
.navigationDestination(HomeDestinations.self)
168168
}
169169
}
@@ -172,22 +172,27 @@ struct RootHomeView: View {
172172
Once defined, they're easy to use.
173173
```swift
174174
Button("Return To Checkpoint Home") {
175-
navigator.returnToCheckpoint(.home)
175+
navigator.returnToCheckpoint(KnownCheckpoints.home)
176176
}
177-
.disabled(!navigator.canReturnToCheckpoint(.home))
177+
.disabled(!navigator.canReturnToCheckpoint(KnownCheckpoints.home))
178178
```
179179
When fired, checkpoints will dismiss any presented screens and pop any pushed views to return *exactly* to the point desired.
180180

181181
Checkpoints can also be used to return values to a caller.
182182
```swift
183-
// Define a checkpoint with a value handler.
184-
.navigationCheckpoint(.settings) { (result: Int) in
183+
// Define a checkpoint with an Int value handler.
184+
extension KnownCheckpoints {
185+
public static var settings: NavigationCheckpoint<Int> { checkpoint() }
186+
}
187+
188+
// Establish the checkpoint and handler in our view
189+
.navigationCheckpoint(KnownCheckpoints.settings) { result in
185190
returnValue = result
186191
}
187192

188193
// Return, passing a value.
189194
Button("Return to Settings Checkpoint Passing Value 5") {
190-
navigator.returnToCheckpoint(.settings, value: 5)
195+
navigator.returnToCheckpoint(KnownCheckpoints.settings, value: 5)
191196
}
192197
```
193198
Checkpoints are a powerful tool. Use them.

0 commit comments

Comments
 (0)