@@ -101,7 +101,7 @@ struct AppView: View {
101
101
)
102
102
.badge (" \( viewStore.unreadActivityCount ) " )
103
103
104
- …
104
+ // ...
105
105
}
106
106
}
107
107
}
@@ -131,7 +131,7 @@ So, instead of performing intense work like this in your reducer:
131
131
132
132
```swift
133
133
case .buttonTapped:
134
- var result = …
134
+ var result = // ...
135
135
for value in someLargeCollection {
136
136
// Some intense computation with value
137
137
}
@@ -144,7 +144,7 @@ and then delivering the result in an action:
144
144
```swift
145
145
case .buttonTapped :
146
146
return .task {
147
- var result = …
147
+ var result = // ...
148
148
for (index, value) in someLargeCollection.enumerated () {
149
149
// Some intense computation with value
150
150
@@ -223,3 +223,45 @@ This greatly reduces the bandwidth of actions being sent into the system so that
223
223
incurring unnecessary costs for sending actions.
224
224
225
225
<!-- ### Memory usage-->
226
+
227
+ ### Compiler performance
228
+
229
+ In very large SwiftUI applications you may experience degraded compiler performance causing long
230
+ compile times, and possibly even compiler failures due to " complex expressions." The
231
+ ``WithViewStore`` helpers that comes with the library can exacerbate that problem for very complex
232
+ views. If you are running into issues using ``WithViewStore`` you can make a small change to your
233
+ view to use an `@ObservedObject ` directly.
234
+
235
+ For example, if your view looks like this:
236
+
237
+ ```swift
238
+ struct FeatureView: View {
239
+ let store: Store<FeatureState, FeatureAction>
240
+
241
+ var body: some View {
242
+ WithViewStore (self .store ) { viewStore in
243
+ // A large, complex view inside here...
244
+ }
245
+ }
246
+ }
247
+ ```
248
+
249
+ ... and you start running into compiler troubles, then you can refactor to the following:
250
+
251
+ ```swift
252
+ struct FeatureView: View {
253
+ let store: Store<FeatureState, FeatureAction>
254
+ @ObservedObject var viewStore: ViewStore<FeatureState, FeatureAction>
255
+
256
+ init (store : Store<FeatureState, FeatureAction>) {
257
+ self .store = store
258
+ self .viewStore = ViewStore (self .store ))
259
+ }
260
+
261
+ var body: some View {
262
+ // A large, complex view inside here...
263
+ }
264
+ }
265
+ ```
266
+
267
+ That should greatly improve the compiler's ability to type- check your view.
0 commit comments