لماذا تحتاج العناصر الفرعية إلى @Binding
افهم تدفق البيانات ثنائي الاتجاه بين الواجهات
لماذا تحتاج العناصر الفرعية إلى @Binding درس مجاني في SwiftUI Academy على CoddyKit. هذا هو الدرس 1 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في SwiftUI Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة SwiftUI Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Two Views, One Truth
When a parent owns a value and a child needs to change it, they must share one source of truth. Otherwise they drift apart. 🔗
The Problem with Copies
If you just pass a value into a child, the child gets a copy. Editing that copy never touches the parents original data.
Enter @Binding
A @Binding is a two-way connection. The child reads and writes the parents value directly, with no copy in between.
Reference, Not a Copy
Think of a binding as a remote control. The child does not own the data; it just holds a reference to where it lives.
Who Owns What
The parent owns the state with @State. The child only borrows it through @Binding. Ownership stays in one clear place.
Two-Way Data Flow
With a binding, changes flow both ways. The parent updates the child, and the child can update the parent. Everything stays in sync.
A Binding in a Child
A child view declares a binding for the value it needs to mutate, marked with the @Binding property wrapper.
struct ChildView: View {
@Binding var isOn: Bool
var body: some View {
Toggle("Lights", isOn: $isOn)
}
}SwiftUI Built on Bindings
You have used bindings already. Toggle, TextField, and Slider all take a binding so they can write back the value you change.
Why It Matters
Bindings let you split a big screen into small, focused child views without losing shared state. This keeps your code reusable. ✨
No Duplicate State
Never copy the same value into both parent and child as separate @State. That creates two truths that quietly disagree.
Single Source, Many Views
One value, many views editing it safely: that is the promise of @Binding. The next lessons show how to wire it up.
Quick Check
Quick check on shared state.
Recap: Sharing One Truth
A parent owns state; a child borrows it with @Binding for safe two-way edits. One source of truth keeps every view in sync. 🎉
الأسئلة الشائعة
هل درس «لماذا تحتاج العناصر الفرعية إلى @Binding» مجاني؟
نعم — نص درس «لماذا تحتاج العناصر الفرعية إلى @Binding» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة SwiftUI Academy، انتقل إلى CoddyKit PRO. تتضمن دورة SwiftUI Academy 4 دروس في المجموع.
ماذا ستتعلم في «لماذا تحتاج العناصر الفرعية إلى @Binding»؟
افهم تدفق البيانات ثنائي الاتجاه بين الواجهات تتمرن على SwiftUI Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ SwiftUI Academy؟
لا تُشترط خبرة سابقة. SwiftUI Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 1 من أصل 4.
كم من الوقت يستغرق درس «لماذا تحتاج العناصر الفرعية إلى @Binding»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس SwiftUI Academy هذا؟
نعم. كل درس في SwiftUI Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- لماذا تحتاج العناصر الفرعية إلى @Binding
- تمرير Binding إلى الأسفل
- بناء صف Toggle قابل لإعادة الاستخدام
- @State مقابل @Binding