不要な再描画を避ける
状態のスコープを絞り、bodyの再評価を最小限にします。
「不要な再描画を避ける」はCoddyKit上の無料SwiftUI Academyレッスンです。 これはレッスン2/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはSwiftUI Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 SwiftUI Academyコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
The Cost of Over-Updating
If a tiny change forces a huge view to rebuild, scrolling stutters. The fix is to keep each redraw as small as possible.
State Lives Where It Changes
Put @State in the smallest view that owns it. Then only that little view re-evaluates when the value flips, not its big parent.
struct Counter: View {
@State private var count = 0
}Extract Subviews
Break a large body into smaller subviews. SwiftUI can then diff and skip the pieces whose inputs did not change.
var body: some View {
HeaderView()
FeedView()
}Pass Only What You Need
Hand a subview just the values it reads. The fewer dependencies a view has, the less often it must recompute.
RowView(title: item.title)Watch Observable Reads
With @Observable models, a view updates only for the exact properties it touches. Read just the fields you display.
Avoid Wide State Objects
One giant model read everywhere makes every change ripple outward. Split it so each view depends on a narrow slice of data.
Beware Closures Capturing Self
A closure that reads many properties widens a view's dependencies. Capture only the specific value the action truly needs.
Move Heavy Work Out of body
Never do expensive computing inside body. It runs often, so cache results in state or a model and read the finished value.
Use let for Constants
Mark unchanging inputs as let. Constant properties never trigger updates, signaling clearly that they cannot cause a redraw.
struct Badge: View {
let label: String
}Equatable Views
For costly subviews, make them Equatable so SwiftUI can compare inputs and skip re-evaluation when they match.
ExpensiveView(data: data)
.equatable()Optimize What You Measure
Do not guess. Scope state, extract views, then measure to confirm you actually shrank the redraws that hurt.
Quick Check
Where should you place state to limit redraws?
Recap: Avoiding Redraws
You learned to scope state tightly, extract subviews, pass minimal data, and keep body cheap. Smaller dependencies mean fewer redraws. ⚡
よくある質問
「不要な再描画を避ける」レッスンは無料ですか?
はい。「不要な再描画を避ける」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、SwiftUI Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 SwiftUI Academyコースには全4レッスンが含まれています。
「不要な再描画を避ける」で何を学びますか?
状態のスコープを絞り、bodyの再評価を最小限にします。 ブラウザで直接実行するハンズオンコードでSwiftUI Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
SwiftUI Academyを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのSwiftUI Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン2/4です。
「不要な再描画を避ける」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このSwiftUI Academyレッスンでコードを書いて実行できますか?
はい。すべてのSwiftUI Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。