Skip to content

Commit

Permalink
[Building Sync-ups Tutorial] fixes in "Navigating to sync-up detail" …
Browse files Browse the repository at this point in the history
…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]>
  • Loading branch information
FredericRuaudel and stephencelis authored Feb 17, 2025
1 parent 013ca04 commit 6d55b5c
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ struct CardView: View {
.font(.caption)
}
.padding()
.foregroundColor(syncUp.theme.accentColor)
.foregroundStyle(syncUp.theme.accentColor)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ struct CardView: View {
.font(.caption)
}
.padding()
.foregroundColor(syncUp.theme.accentColor)
.foregroundStyle(syncUp.theme.accentColor)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ struct CardView: View {
.font(.caption)
}
.padding()
.foregroundColor(syncUp.theme.accentColor)
.foregroundStyle(syncUp.theme.accentColor)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct SyncUpsListView: View {

var body: some View {
List {
ForEach(store.$syncUps) { $syncUp in
ForEach(Array(store.$syncUps)) { $syncUp in
NavigationLink(
state: AppFeature.Path.State.detail(SyncUpDetail.State(syncUp: <#Shared<SyncUp>#>))
) {
Expand Down Expand Up @@ -66,7 +66,7 @@ struct CardView: View {
.font(.caption)
}
.padding()
.foregroundColor(syncUp.theme.accentColor)
.foregroundStyle(syncUp.theme.accentColor)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ struct CardView: View {
.font(.caption)
}
.padding()
.foregroundColor(syncUp.theme.accentColor)
.foregroundStyle(syncUp.theme.accentColor)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,12 @@
element in the collection.

@Step {
Pass the shared collection to the `ForEach` to derive a `Shared<SyncUp>` for each element in
the `Shared<IdentifiedArrayOf<SyncUp>>`.
Convert the shared collection of sync-ups into a collection of shared sync-ups and pass it
along to `ForEach`.

> Tip: While we use an `Array` initializer to do this conversion, it is possible to use any range
> replaceable collection.

@Code(name: "SyncUpsList.swift", file: SyncUpDetailNavigation-03-code-0003.swift)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct AppFeatureTests {
AppFeature()
}

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

await store.send(\.path.push, (id: 0, .detail(SyncUpDetail.State(syncUp: sharedSyncUp)))) {
$0.path[id: 0] = .detail(SyncUpDetail.State(syncUp: sharedSyncUp))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ struct AppFeatureTests {
AppFeature()
}

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

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

await store.send(\.path[id:0].detail.deleteButtonTapped) {
$0.path[id: 0]?.detail?.destination = .alert(.deleteSyncUp)
$0.path[id: 0, case: \.detail]?.destination = .alert(.deleteSyncUp)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ struct AppFeatureTests {
AppFeature()
}

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

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

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

await store.send(\.path[id:0].detail.destination.alert.confirmButtonTapped) {
$0.path[id: 0, case: \.detail]?.destination = nil
$0.syncUpsList.syncUps = []
$0.syncUpsList.$syncUps.withLock { $0 = [] }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ struct AppFeatureTests {
AppFeature()
}

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

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

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

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

await store.receive(\.path.popFrom) {
Expand Down

0 comments on commit 6d55b5c

Please sign in to comment.