الأخطاء الشائعة وأخطاء المترجم
إصلاح حالات الفشل المعتادة من نوع 'no actual declaration'
الأخطاء الشائعة وأخطاء المترجم درس مجاني في Kotlin Multiplatform Academy على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Kotlin Multiplatform Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Kotlin Multiplatform Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Errors Are Your Friend
expect/actual mistakes surface at compile time, never as silent runtime bugs. Learning the messages makes fixing them fast. 🛠️
No actual Declaration
The most common error is forgetting an actual for one target. The compiler says expected declaration has no actual for that platform.
Fix the Missing actual
Add the implementation in the right source set, like iosMain. Once every target has its actual, the build goes green.
actual fun platform(): String = "iOS"Signature Mismatch
If your actual changes the return type or parameters, the compiler reports that the actual does not match the expect. Align them exactly.
Forgetting the actual Keyword
An implementation without the actual keyword looks like a separate function to the compiler, so it still complains the expect is unfulfilled.
Wrong Source Set
Putting an actual in the wrong folder means a target still has no match. Each actual must sit in its platform's source set.
Package Must Match
The actual has to share the exact package of its expect. A mismatched package leaves the expect looking unimplemented.
package com.app.coreImporting Platform Types in Common
Using Android's Build or iOS UIDevice inside commonMain fails to resolve. Keep platform imports inside their own source sets only.
Default Args Belong on expect
Declare default parameter values on the expect, not the actual. Repeating defaults on an actual triggers a compiler error.
Read the Message Carefully
Kotlin's errors usually name the exact target and member. Treat the message as a checklist and the fix is almost always obvious. 💡
Build All Targets
Compile every target, not just Android. An iOS-only gap stays hidden until you build the iOS framework as well.
Quick Check
Spot the cause of the classic error.
Recap
You can now diagnose the usual expect/actual failures: a missing actual, a signature or package mismatch, or a platform import in common code. 🎉
الأسئلة الشائعة
هل درس «الأخطاء الشائعة وأخطاء المترجم» مجاني؟
نعم — نص درس «الأخطاء الشائعة وأخطاء المترجم» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Kotlin Multiplatform Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Kotlin Multiplatform Academy 4 دروس في المجموع.
ماذا ستتعلم في «الأخطاء الشائعة وأخطاء المترجم»؟
إصلاح حالات الفشل المعتادة من نوع 'no actual declaration' تتمرن على Kotlin Multiplatform Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Kotlin Multiplatform Academy؟
لا تُشترط خبرة سابقة. Kotlin Multiplatform Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.
كم من الوقت يستغرق درس «الأخطاء الشائعة وأخطاء المترجم»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Kotlin Multiplatform Academy هذا؟
نعم. كل درس في Kotlin Multiplatform Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- لماذا توجد expect/actual
- الحصول على اسم المنصة لكل هدف
- فئات وخصائص expect/actual
- الأخطاء الشائعة وأخطاء المترجم