We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent fb49650 commit f93688eCopy full SHA for f93688e
Guide.docc/Articles/MakeInitializerLowCost.md
@@ -2,4 +2,32 @@
2
Viewのイニシャライザは何度も呼び出されるため、低コストに保ちます。
3
4
## Overview
5
+高コストなイニシャライザはよくあるパフォーマンス低下の原因です。
6
+
7
+```swift
8
+struct DogRootView: View {
9
+ @State private var model = FetchModel()
10
11
+ var body: some View {
12
+ DogList(model.dogs)
13
+ }
14
+}
15
16
+@Observable class FetchModel {
17
+ var dogs: [Dog]
18
19
+ init() {
20
+ fetchDogs()
21
22
23
+ func fetchDogs() {
24
+ // Takes a long time
25
26
27
+```
28
29
+この例では`DogRootView`のイニシャライザで`FetchModel`がイニシャライズされます。
30
+`FetchModel`のイニシャライザで処理に時間のかかる`fetchDogs`が同期的に呼び出されているため、`DogRootView`のイニシャライザが高コストとなっています。
31
32
+### `.task`でイニシャライザのコストを下げる
33
xxx
0 commit comments