بنية ملف تطبيق SwiftUI
تعرّف على @main وApp وWindowGroup وContentView
بنية ملف تطبيق SwiftUI درس مجاني في SwiftUI Academy على CoddyKit. هذا هو الدرس 2 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في SwiftUI Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة SwiftUI Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
The App File
Every SwiftUI project has a file named after your app, like MyFirstApp.swift. This app file is the true entry point where your whole app begins. 📱
The @main Marker
The @main attribute tells Swift exactly where your program starts. iOS launches your app by running the type marked with it.
@main
struct MyFirstApp: App {
}Conforming to App
Your main struct conforms to the App protocol. This is the SwiftUI blueprint for an application, describing what scenes it shows.
The body Property
Inside the App struct, a body property describes your app's scenes. SwiftUI reads it to know what to display when the app launches.
var body: some Scene {
WindowGroup {
ContentView()
}
}Scenes, Not Views
The app's body returns a Scene, not a View. A scene is a container for a window or screen that holds your actual views inside it.
WindowGroup
WindowGroup is the most common scene. It manages your app's main window and, on iPhone, simply fills the whole screen.
Your Root View
Inside WindowGroup you place your root view, usually ContentView(). It is the first screen the user sees when the app opens.
ContentView Lives Apart
ContentView sits in its own file, separate from the app file. Keeping the entry point and the UI apart keeps your project tidy and clear.
How It Flows
The chain is simple: @main starts the App, the App shows a WindowGroup, and the WindowGroup displays your ContentView. ✨
One @main Only
An app can have just one @main entry point. The template already provides it, so you rarely add or change this part yourself.
Where You Work
You will spend most of your time editing views like ContentView, not the app file. The app file mostly just wires everything together.
Quick Check
What is the job of the WindowGroup scene in the app file?
Recap
You learned the chain: @main on the App struct returns a WindowGroup scene that shows ContentView. That is how a SwiftUI app boots up. 🧩
الأسئلة الشائعة
هل درس «بنية ملف تطبيق SwiftUI» مجاني؟
نعم — نص درس «بنية ملف تطبيق SwiftUI» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة SwiftUI Academy، انتقل إلى CoddyKit PRO. تتضمن دورة SwiftUI Academy 4 دروس في المجموع.
ماذا ستتعلم في «بنية ملف تطبيق SwiftUI»؟
تعرّف على @main وApp وWindowGroup وContentView تتمرن على SwiftUI Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ SwiftUI Academy؟
لا تُشترط خبرة سابقة. SwiftUI Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 2 من أصل 4.
كم من الوقت يستغرق درس «بنية ملف تطبيق SwiftUI»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس SwiftUI Academy هذا؟
نعم. كل درس في SwiftUI Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- تثبيت Xcode وإنشاء مشروع
- بنية ملف تطبيق SwiftUI
- لوحة المعاينة المباشرة
- التشغيل على المحاكي والجهاز