Skip to content

Commit b4e5ff5

Browse files
stephencelismbrandonw
authored andcommitted
Fix UIKit Case Study warning (#924)
* Fix UIKit Case Study warning * wip Co-authored-by: Brandon Williams <[email protected]>
1 parent fe425a1 commit b4e5ff5

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

Examples/CaseStudies/UIKitCaseStudies/CounterViewController.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import ComposableArchitecture
33
import SwiftUI
44
import UIKit
55

6-
struct CounterState: Equatable {
6+
struct CounterState: Equatable, Identifiable {
7+
let id = UUID()
78
var count = 0
89
}
910

Examples/CaseStudies/UIKitCaseStudies/ListsOfState.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ import SwiftUI
44
import UIKit
55

66
struct CounterListState: Equatable {
7-
var counters: [CounterState] = []
7+
var counters: IdentifiedArrayOf<CounterState> = []
88
}
99

1010
enum CounterListAction: Equatable {
11-
case counter(index: Int, action: CounterAction)
11+
case counter(id: CounterState.ID, action: CounterAction)
1212
}
1313

1414
struct CounterListEnvironment {}
1515

1616
let counterListReducer: Reducer<CounterListState, CounterListAction, CounterListEnvironment> =
1717
counterReducer.forEach(
1818
state: \CounterListState.counters,
19-
action: /CounterListAction.counter(index:action:),
19+
action: /CounterListAction.counter(id:action:),
2020
environment: { _ in CounterEnvironment() }
2121
)
2222

@@ -61,11 +61,12 @@ final class CountersTableViewController: UITableViewController {
6161
}
6262

6363
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
64+
let counter = self.viewStore.counters[indexPath.row]
6465
self.navigationController?.pushViewController(
6566
CounterViewController(
6667
store: self.store.scope(
67-
state: \.counters[indexPath.row],
68-
action: { .counter(index: indexPath.row, action: $0) }
68+
state: { _ in counter },
69+
action: { .counter(id: counter.id, action: $0) }
6970
)
7071
),
7172
animated: true

Examples/CaseStudies/tvOSCaseStudies/FocusView.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,13 @@ let focusReducer = Reducer<FocusState, FocusAction, FocusEnvironment> {
4848
.padding()
4949

5050
HStack(spacing: 40) {
51-
ForEach(1..<11) { index in
51+
ForEach(1..<6) { index in
52+
Button(numbers[index]) {}
53+
.prefersDefaultFocus(viewStore.currentFocus == index, in: self.namespace)
54+
}
55+
}
56+
HStack(spacing: 40) {
57+
ForEach(6..<11) { index in
5258
Button(numbers[index]) {}
5359
.prefersDefaultFocus(viewStore.currentFocus == index, in: self.namespace)
5460
}

0 commit comments

Comments
 (0)