Skip to content

Commit aede577

Browse files
sillygooseRick Narostephencelismbrandonw
authored andcommitted
Fixes for the 'Basic Usage' to allow project to build and run (#1507)
* fixes for building basic usage section without error * and code with too many closing braces * adjust description * burned by xcode expanding the code * burned by xcode case indent option * fixed added spaces * Apply suggestions from code review Co-authored-by: Brandon Williams <[email protected]> Co-authored-by: Rick Naro <[email protected]> Co-authored-by: Stephen Celis <[email protected]> Co-authored-by: Brandon Williams <[email protected]> (cherry picked from commit e726a132929be7a67050e2587b9d2b1532898ba8)
1 parent 2cc6f7e commit aede577

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

README.md

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ As a basic example, consider a UI that shows a number along with "+" and "−" b
9999
To implement this feature we create a new type that will house the domain and behavior of the feature by conforming to `ReducerProtocol`:
100100

101101
```swift
102+
import ComposableArchitecture
103+
102104
struct Feature: ReducerProtocol {
103105
}
104106
```
@@ -151,13 +153,13 @@ struct Feature: ReducerProtocol {
151153
return .none
152154

153155
case .numberFactButtonTapped:
154-
return .task { [count = state.count] in
156+
return .task { [count = state.count] in
155157
await .numberFactResponse(
156-
TaskResult {
158+
TaskResult {
157159
String(
158160
decoding: try await URLSession.shared
159-
.data(from: URL(string: "http://numbersapi.com/\(number)/trivia")!).0,
160-
using: UTF8.self
161+
.data(from: URL(string: "http://numbersapi.com/\(count)/trivia")!).0,
162+
as: UTF8.self
161163
)
162164
}
163165
)
@@ -170,7 +172,6 @@ struct Feature: ReducerProtocol {
170172
case .numberFactResponse(.failure):
171173
state.numberFactAlert = "Could not load a number fact :("
172174
return .none
173-
}
174175
}
175176
}
176177
}
@@ -274,15 +275,19 @@ It is also straightforward to have a UIKit controller driven off of this store.
274275
Once we are ready to display this view, for example in the app's entry point, we can construct a store. This can be done by specifying the initial state to start the application in, as well as the reducer that will power the application:
275276

276277
```swift
278+
import ComposableArchitecture
279+
277280
@main
278281
struct MyApp: App {
279282
var body: some Scene {
280-
FeatureView(
281-
store: Store(
282-
initialState: Feature.State(),
283-
reducer: Feature()
283+
WindowGroup {
284+
FeatureView(
285+
store: Store(
286+
initialState: Feature.State(),
287+
reducer: Feature()
288+
)
284289
)
285-
)
290+
}
286291
}
287292
}
288293
```

0 commit comments

Comments
 (0)