0Pricing
SwiftUI Academy · درس

تمرير Binding إلى الأسفل

مرّر الحالة إلى واجهة فرعية باستخدام علامة الدولار

تمرير Binding إلى الأسفل درس مجاني في SwiftUI Academy على CoddyKit. هذا هو الدرس 2 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في SwiftUI Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة SwiftUI Academy 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

The Dollar Sign

To turn @State into a binding you pass it, prefix the property with a dollar sign. That hands the child a live connection.

Value vs Binding

Plain name gives the current value. The dollar-prefixed name gives the binding. Same property, two ways to use it.

var count = 0
// count   -> the value
// $count  -> the binding

Owning the State

The parent declares the source with @State. Only the owner of state can create a binding from it.

struct Parent: View {
    @State private var isOn = false
    var body: some View { Text("Placeholder") }
}

Handing It Off

Inside the parents body, pass the binding into the child by writing the property name with a dollar sign in front.

var body: some View {
    ChildView(isOn: $isOn)
}

The Child Receives It

The child stores the connection in a @Binding property. Its type matches the value, like Bool or String.

struct ChildView: View {
    @Binding var isOn: Bool
    var body: some View { Toggle("On", isOn: $isOn) }
}

Types Must Match

A binding to a Bool plugs only into a @Binding var isOn: Bool. Mismatched types stop the build until you fix them.

Editing Flows Up

When the child flips its toggle, the change travels straight back to the parents @State. The parent re-renders automatically.

Forgot the Dollar Sign?

Pass the bare value where a binding is expected and Swift complains. The dollar sign is what makes it a binding.

Bindings Go Deep

A child can pass its binding further down to its own children. The same dollar sign threads state through many layers.

Read in the Child

Inside the child, use the plain name to read the current value and the dollar name when a control needs the binding back.

Text(isOn ? "On" : "Off")
Toggle("Power", isOn: $isOn)

One Line, Two Way

That single dollar-prefixed argument wires up full two-way sync. Tiny syntax, big power behind the binding. ⚡

Quick Check

Quick check on passing bindings.

Recap: The Dollar Sign Bridge

Own state with @State, pass it down with the dollar sign, receive it as @Binding. That bridge keeps parent and child in sync. 🌉

الأسئلة الشائعة

هل درس «تمرير Binding إلى الأسفل» مجاني؟

نعم — نص درس «تمرير Binding إلى الأسفل» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة SwiftUI Academy، انتقل إلى CoddyKit PRO. تتضمن دورة SwiftUI Academy 4 دروس في المجموع.

ماذا ستتعلم في «تمرير Binding إلى الأسفل»؟

مرّر الحالة إلى واجهة فرعية باستخدام علامة الدولار تتمرن على SwiftUI Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ SwiftUI Academy؟

لا تُشترط خبرة سابقة. SwiftUI Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 2 من أصل 4.

كم من الوقت يستغرق درس «تمرير Binding إلى الأسفل»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس SwiftUI Academy هذا؟

نعم. كل درس في SwiftUI Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. لماذا تحتاج العناصر الفرعية إلى @Binding
  2. تمرير Binding إلى الأسفل
  3. بناء صف Toggle قابل لإعادة الاستخدام
  4. @State مقابل @Binding
← العودة إلى SwiftUI Academy