سؤال 1 — Struct vs Class

الفرق الجوهري:

  • struct = value type → لما بتبعته لمتغير تاني، بيتنسخ
  • class = reference type → بيتشارك نفس الـ object في الميموري

نقاط لازم تذكرها:

  • Struct على الـ stack (أسرع)، Class على الـ heap (ARC بيتحكم فيه)
  • Class بيدعم inheritance، Struct لأ
  • في SwiftUI كل الـ views هي structs
  • Apple نفسها بتقول: ابدأ بـ struct، وروّح لـ class لو محتاج inheritance أو shared state

جملة تقولها في المقابلة:

"In Swift, structs are value types copied on assignment, while classes are reference types sharing the same instance. I prefer structs for data models especially in SwiftUI, and only use classes when I need inheritance or shared mutable state."


سؤال 2 — Optionals

الفكرة الأساسية:

Optional معناها إن المتغير ممكن يكون فيه قيمة أو nil — Swift بيجبرك تتعامل مع الاحتمالين عشان متحصلش crash.

طرق الـ unwrapping:

الطريقة امتى تستخدمها
if let لو محتاج القيمة جوه block محدود
guard let لو القيمة مش موجودة تخرج من الـ function
?? (nil coalescing) تدي قيمة default لو nil
! (force unwrap) بس لو متأكد 100% مش nil — خطر
Optional chaining ?. توصل لـ property من غير crash

جملة تقولها في المقابلة:

"Optionals in Swift represent a value that may or may not exist. I prefer using guard let at the top of functions to unwrap early and exit cleanly, and ?? for default values. I avoid force unwrapping unless I'm absolutely certain the value exists."


سؤال 3 — Async/Await & Concurrency

الفكرة الأساسية:

بدل ما تستخدم completion handlers (الـ callbacks القديمة)، Swift من إصدار 5.5 بيخليك تكتب كود asynchronous بشكل نظيف زي ما بتكتب synchronous.

المفاهيم اللي لازم تعرفها:

المفهوم معناه
async الـ function دي ممكن تاخد وقت
await استنى النتيجة من غير ما تبلوك الـ thread
Task { } عشان تشغل async code من مكان sync
@MainActor خلي الكود يشتغل على الـ main thread (UI updates)
Structured concurrency async let و TaskGroup لتشغيل أكتر من حاجة بالتوازي

مثال بسيط:

swift
func fetchUser() async throws -> User {
    let data = try await URLSession.shared.data(from: url)
    return try JSONDecoder().decode(User.self, from: data.0)
}

نقطة مهمة للوظيفة دي: لو AI كتب إجابة عن concurrency ومش ذكر @MainActor أو تكلم عن DispatchQueue بس من غير ما يذكر async/await — ده نقص واضح تقيّمه.

جملة تقولها في المقابلة:

"Swift concurrency uses async/await to write asynchronous code cleanly. I use Task to bridge sync and async contexts, and @MainActor to ensure UI updates happen on the main thread. I also understand structured concurrency with async let for parallel work."


سؤال 4 — @State, @Binding, @ObservedObject

الفكرة الأساسية:

دي الـ property wrappers اللي SwiftUI بيستخدمها لإدارة الـ data وتحديد مين المسؤول عن الـ state.


الفرق بينهم:

الـ Wrapper المسؤولية امتى تستخدمه
@State الـ view بتمتلك الـ data data بسيطة داخل view واحدة
@Binding مش بتمتلك — بتتشارك من parent تمرير state من parent لـ child
@ObservedObject تراقب object خارجي ViewModel مشترك بين views
@StateObject تنشئ وتمتلك الـ object أول view بتعمل الـ ViewModel

مثال عملي:

swift
// Parent
@State private var isOn = false
Toggle("Switch", isOn: $isOn) // $ = Binding

// Child
struct MyToggle: View {
    @Binding var isOn: Bool
}

نقطة مهمة: الفرق بين @StateObject و @ObservedObject — كتير بيغلطوا فيها:

  • @StateObject → الـ view دي هي اللي بتعمل الـ object (owner)
  • @ObservedObject → الـ object جاي من بره (observer فقط)

جملة تقولها في المقابلة:

"@State is for local view-owned data, @Binding passes a reference to that state down to child views, and @ObservedObject watches an external ViewModel. A common mistake I look for in AI responses is confusing @StateObject with @ObservedObject — the first owns the object, the second just observes it."


سؤال 5 — UserDefaults

الفكرة الأساسية:

UserDefaults هو نظام تخزين بسيط لـ key-value pairs — مصمم للـ preferences والإعدادات الصغيرة، مش للداتا الكبيرة.


امتى تستخدم UserDefaults:

✅ إعدادات المستخدم (dark mode, language) ✅ قيم بسيطة (Bool, Int, String) ✅ آخر تاريخ فتح التطبيق ✅ onboarding completed flag


امتى متستخدمهوش:

❌ قوائم وبيانات كتيرة ❌ صور أو ملفات ❌ بيانات حساسة (passwords → استخدم Keychain) ❌ داتا علاقات معقدة


البدائل الصح:

الاحتياج الحل
داتا كتيرة ومعقدة CoreData أو SwiftData
ملفات FileManager
بيانات حساسة Keychain
داتا بسيطة مؤقتة UserDefaults ✅

ليه السؤال ده مهم للوظيفة:

لو AI اقترح UserDefaults لتخزين قائمة مستخدمين أو بيانات كبيرة — ده خطأ واضح لازم تشوفه وتقيّمه وتقول ليه غلط وإيه البديل الصح.

جملة تقولها في المقابلة:

"UserDefaults is designed for small key-value preferences like settings and flags. Using it for large or complex data is a common mistake I'd flag in an AI response — the correct alternatives are CoreData or SwiftData for structured data, and Keychain for sensitive information."


سؤال 6 — إزاي تقيّم إجابة AI

الفكرة الأساسية:

الوظيفة دي مش بس عارف Swift — لازم تعرف تحكم على جودة إجابة بشكل منهجي. المقابلة هتحكم عليك بالمعيارين دول مع بعض.


الـ Framework اللي تستخدمه عند التقييم:

المعيار السؤال اللي بتسأله
Correctness الكود شغال؟ المعلومة صح؟
Completeness فيه حاجة ناقصة مهمة؟
Clarity الشرح واضح لمستوى السؤال؟
Best Practices بيتبع Apple guidelines؟
Edge Cases اتكلم عن الحالات الاستثنائية؟

أمثلة على أخطاء شائعة في إجابات AI:

❌ يقول استخدم DispatchQueue من غير ما يذكر async/await ❌ يقترح UserDefaults لداتا كبيرة ❌ يخلط بين @StateObject و @ObservedObject ❌ يكتب force unwrap ! من غير تحذير ❌ يشرح بطريقة معقدة جداً لسؤال مبتدئ


إزاي تبني إجابتك في المقابلة:

لو سألوك "قيّم الإجابة دي":

  1. اقرأ الإجابة كاملة الأول
  2. حدد الصح فيها — مش بس الغلط
  3. حدد الخطأ أو النقص بدقة
  4. اقترح التصحيح مع السبب
  5. دي Rate من 10 مع تبرير

جملة تقولها في المقابلة:

"When evaluating an AI response, I check five things: correctness, completeness, clarity, adherence to Apple best practices, and handling of edge cases. I always acknowledge what the response got right before pointing out errors, and I always suggest a concrete fix — not just flag the problem."


خلاصة الـ 6 أسئلة كلها 🎯

السؤال الكلمة المفتاحية
Struct vs Class Value type / Reference type / SwiftUI prefers structs
Optionals guard let / ?? / avoid force unwrap
Async/Await @MainActor / Task / structured concurrency
@State/@Binding Ownership / source of truth / @StateObject vs @ObservedObject
UserDefaults Small key-value only / CoreData للداتا الكبيرة
AI Evaluation Correctness / Completeness / Best Practices

دلوقتي روح جرب الـ simulator اللي عملناه وجاوب بكلامك إنت — هتلاقي الإجابات طالعة بشكل طبيعي. 💪