Skip to content

Commit 6d55b5c

Browse files
[Building Sync-ups Tutorial] fixes in "Navigating to sync-up detail" chapter (#3581)
* Update CardView to use foregroundStyle instead of deprecated foregroundColor * Update SyncUps tutorial code to use Array with shared collection in ForEach * refactor: update shared SyncUp and path handling to fix compilation errors - Encapsulate `sharedSyncUp` with `Shared`. - Update path manipulation to use case-based access. - Update `syncUps` list with locking mechanism. * Update Sources/ComposableArchitecture/Documentation.docc/Tutorials/BuildingSyncUps/07-SyncUpDetailNavigation/SyncUpDetailNavigation.tutorial --------- Co-authored-by: Stephen Celis <[email protected]>
1 parent 013ca04 commit 6d55b5c

10 files changed

+21
-17
lines changed

Sources/ComposableArchitecture/Documentation.docc/Tutorials/BuildingSyncUps/07-SyncUpDetailNavigation/SyncUpDetailNavigation-03-code-0001-previous.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ struct CardView: View {
6666
.font(.caption)
6767
}
6868
.padding()
69-
.foregroundColor(syncUp.theme.accentColor)
69+
.foregroundStyle(syncUp.theme.accentColor)
7070
}
7171
}
7272

Sources/ComposableArchitecture/Documentation.docc/Tutorials/BuildingSyncUps/07-SyncUpDetailNavigation/SyncUpDetailNavigation-03-code-0001.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ struct CardView: View {
6666
.font(.caption)
6767
}
6868
.padding()
69-
.foregroundColor(syncUp.theme.accentColor)
69+
.foregroundStyle(syncUp.theme.accentColor)
7070
}
7171
}
7272

Sources/ComposableArchitecture/Documentation.docc/Tutorials/BuildingSyncUps/07-SyncUpDetailNavigation/SyncUpDetailNavigation-03-code-0002.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ struct CardView: View {
6666
.font(.caption)
6767
}
6868
.padding()
69-
.foregroundColor(syncUp.theme.accentColor)
69+
.foregroundStyle(syncUp.theme.accentColor)
7070
}
7171
}
7272

Sources/ComposableArchitecture/Documentation.docc/Tutorials/BuildingSyncUps/07-SyncUpDetailNavigation/SyncUpDetailNavigation-03-code-0003.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ struct SyncUpsListView: View {
1111

1212
var body: some View {
1313
List {
14-
ForEach(store.$syncUps) { $syncUp in
14+
ForEach(Array(store.$syncUps)) { $syncUp in
1515
NavigationLink(
1616
state: AppFeature.Path.State.detail(SyncUpDetail.State(syncUp: <#Shared<SyncUp>#>))
1717
) {
@@ -66,7 +66,7 @@ struct CardView: View {
6666
.font(.caption)
6767
}
6868
.padding()
69-
.foregroundColor(syncUp.theme.accentColor)
69+
.foregroundStyle(syncUp.theme.accentColor)
7070
}
7171
}
7272

Sources/ComposableArchitecture/Documentation.docc/Tutorials/BuildingSyncUps/07-SyncUpDetailNavigation/SyncUpDetailNavigation-03-code-0004.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ struct CardView: View {
6666
.font(.caption)
6767
}
6868
.padding()
69-
.foregroundColor(syncUp.theme.accentColor)
69+
.foregroundStyle(syncUp.theme.accentColor)
7070
}
7171
}
7272

Sources/ComposableArchitecture/Documentation.docc/Tutorials/BuildingSyncUps/07-SyncUpDetailNavigation/SyncUpDetailNavigation.tutorial

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,12 @@
238238
element in the collection.
239239

240240
@Step {
241-
Pass the shared collection to the `ForEach` to derive a `Shared<SyncUp>` for each element in
242-
the `Shared<IdentifiedArrayOf<SyncUp>>`.
241+
Convert the shared collection of sync-ups into a collection of shared sync-ups and pass it
242+
along to `ForEach`.
243+
244+
> Tip: While we use an `Array` initializer to do this conversion, it is possible to use any range
245+
> replaceable collection.
246+
243247
@Code(name: "SyncUpsList.swift", file: SyncUpDetailNavigation-03-code-0003.swift)
244248
}
245249

Sources/ComposableArchitecture/Documentation.docc/Tutorials/BuildingSyncUps/07-SyncUpDetailNavigation/TestingNavigation-01-code-0005.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ struct AppFeatureTests {
1414
AppFeature()
1515
}
1616

17-
let sharedSyncUp = try #require($syncUps[id: syncUp.id])
17+
let sharedSyncUp = try #require(Shared($syncUps[id: syncUp.id]))
1818

1919
await store.send(\.path.push, (id: 0, .detail(SyncUpDetail.State(syncUp: sharedSyncUp)))) {
2020
$0.path[id: 0] = .detail(SyncUpDetail.State(syncUp: sharedSyncUp))

Sources/ComposableArchitecture/Documentation.docc/Tutorials/BuildingSyncUps/07-SyncUpDetailNavigation/TestingNavigation-01-code-0006.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ struct AppFeatureTests {
1414
AppFeature()
1515
}
1616

17-
let sharedSyncUp = try #require($syncUps[id: syncUp.id])
17+
let sharedSyncUp = try #require(Shared($syncUps[id: syncUp.id]))
1818

1919
await store.send(\.path.push, (id: 0, .detail(SyncUpDetail.State(syncUp: sharedSyncUp)))) {
2020
$0.path[id: 0] = .detail(SyncUpDetail.State(syncUp: sharedSyncUp))
2121
}
2222

2323
await store.send(\.path[id:0].detail.deleteButtonTapped) {
24-
$0.path[id: 0]?.detail?.destination = .alert(.deleteSyncUp)
24+
$0.path[id: 0, case: \.detail]?.destination = .alert(.deleteSyncUp)
2525
}
2626
}
2727
}

Sources/ComposableArchitecture/Documentation.docc/Tutorials/BuildingSyncUps/07-SyncUpDetailNavigation/TestingNavigation-01-code-0007.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@ struct AppFeatureTests {
1414
AppFeature()
1515
}
1616

17-
let sharedSyncUp = try #require($syncUps[id: syncUp.id])
17+
let sharedSyncUp = try #require(Shared($syncUps[id: syncUp.id]))
1818

1919
await store.send(\.path.push, (id: 0, .detail(SyncUpDetail.State(syncUp: sharedSyncUp)))) {
2020
$0.path[id: 0] = .detail(SyncUpDetail.State(syncUp: sharedSyncUp))
2121
}
2222

2323
await store.send(\.path[id:0].detail.deleteButtonTapped) {
24-
$0.path[id: 0]?.detail?.destination = .alert(.deleteSyncUp)
24+
$0.path[id: 0, case: \.detail]?.destination = .alert(.deleteSyncUp)
2525
}
2626

2727
await store.send(\.path[id:0].detail.destination.alert.confirmButtonTapped) {
2828
$0.path[id: 0, case: \.detail]?.destination = nil
29-
$0.syncUpsList.syncUps = []
29+
$0.syncUpsList.$syncUps.withLock { $0 = [] }
3030
}
3131
}
3232
}

Sources/ComposableArchitecture/Documentation.docc/Tutorials/BuildingSyncUps/07-SyncUpDetailNavigation/TestingNavigation-01-code-0008.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@ struct AppFeatureTests {
1414
AppFeature()
1515
}
1616

17-
let sharedSyncUp = try #require($syncUps[id: syncUp.id])
17+
let sharedSyncUp = try #require(Shared($syncUps[id: syncUp.id]))
1818

1919
await store.send(\.path.push, (id: 0, .detail(SyncUpDetail.State(syncUp: sharedSyncUp)))) {
2020
$0.path[id: 0] = .detail(SyncUpDetail.State(syncUp: sharedSyncUp))
2121
}
2222

2323
await store.send(\.path[id:0].detail.deleteButtonTapped) {
24-
$0.path[id: 0]?.detail?.destination = .alert(.deleteSyncUp)
24+
$0.path[id: 0, case: \.detail]?.destination = .alert(.deleteSyncUp)
2525
}
2626

2727
await store.send(\.path[id:0].detail.destination.alert.confirmButtonTapped) {
2828
$0.path[id: 0, case: \.detail]?.destination = nil
29-
$0.syncUpsList.syncUps = []
29+
$0.syncUpsList.$syncUps.withLock { $0 = [] }
3030
}
3131

3232
await store.receive(\.path.popFrom) {

0 commit comments

Comments
 (0)