ခဏလေး ဒီလိုပဲ စဉ်းစားကြည့်
ဒီ round က learn ခဲ့ပြီးသား Basic/Intermediate concept တွေကို လက်တွေ့ ပြန်စမ်းကြည့်ဖို့ round ပါ — View/@State/Modifier ကို ခွဲသိခြင်း, SwiftUI code ထဲက error ကို ရှာဖွေခြင်း, `@State` ကို မှန်ကန်စွာ သုံးတတ်ခြင်းကိုပဲ ကိုယ်တိုင် လက်တွေ့ လုပ်ကြည့်ရမှာပါ။ Task တစ်ခုချင်းစီက ၅ မိနစ်ထက် မကြာသင့်ပါဘူး။
လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်
Task 1: 'View protocol', '@State', 'Modifier' သုံးလုံးရဲ့ တာဝန် ကွာခြားချက်ကို ဝါကျတစ်ကြောင်းစီနဲ့ ရှင်းပြပါ။ Task 2: `var count = 0` (`@State` မပါ) ကို View struct ထဲမှာ ရေးပြီး Button tap ရင် `count += 1` လုပ်ထားရင် ဘာဖြစ်မလဲ ခန့်မှန်းပြီး ရေးပါ။ Task 3: `List` ကို ဘယ်အခါ VStack+ForEach အစား သုံးသင့်လဲ ဥပမာနဲ့တကွ ရေးပါ။ Task 4: `@State` နဲ့ `@Binding` ရဲ့ ကွာခြားချက်ကို parent-child View ဆက်သွယ်ပုံ ဥပမာနဲ့ ရှင်းပါ။
အတူတူ ကြည့်မယ်
# Task 2 - mutable property without @State
var count = 0 // NOT wrapped in @State!
Button("Increment") { count += 1 }
Result: this is a compile-time error — SwiftUI View is a
struct (immutable), so a plain `var` property cannot be
mutated from inside a closure. The compiler says
"Cannot assign to property: 'self' is immutable".
@State is required to make it mutable.
# Task 4 - @State vs @Binding
@State = the View that OWNS the value (private, source of truth)
@Binding = a child View that needs to READ AND WRITE a value
it doesn't own — the parent passes it in with $View/@State/Modifier ကွာခြားချက်၊ @State-less compile error၊ @State vs @Binding ဆုံးဖြတ်ချက် ရရှိလာမည်။၅ မိနစ် စမ်းကြည့်
ကိုယ်ပိုင် View တစ်ခု ရေးပြီး တမင် `@State` မထည့်ဘဲ mutable property bug ထည့်ကြည့်ပါ — Xcode ရဲ့ compile error message ကို ကိုယ်တိုင် ဖတ်ကြည့်ပါ။
သတိလေးတစ်ချက်
ဒီ round မှာ physical device setup လုပ်ဖို့ မလိုပါဘူး — Simulator (ဒါမှမဟုတ် #Preview panel) ကိုပဲ အဓိကထား practice လုပ်ခြင်းပါ။