0Pricing
Kotlin Multiplatform Academy · درس

استخدام أطر Apple من Kotlin

الوصول مباشرةً إلى platform.Foundation وما شابهها

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

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

Apple APIs, in Kotlin

Kotlin/Native ships with ready-made bindings for Apple platforms. From iosMain you can call Foundation, UIKit and more directly in Kotlin. 🍎

The platform Packages

Every Apple framework lives under a platform package. Import platform.Foundation, platform.UIKit, or platform.CoreLocation just like any Kotlin package.

import platform.Foundation.NSDate
import platform.UIKit.UIDevice

A First Foundation Call

Try NSDate. Creating one gives you the current moment, exactly as Swift would, but the code stays in your shared iosMain source set.

val now = NSDate()
println(now.description())

UIKit Without Leaving Kotlin

Need the device name or OS version? UIDevice.currentDevice hands it over so platform code reads naturally in Kotlin.

val v = UIDevice.currentDevice.systemVersion
println("iOS " + v)

iosMain Is the Right Home

These bindings exist only on iOS targets. Put any Apple-framework call in iosMain, never in commonMain, or the Android build breaks.

Objective-C Becomes Kotlin

The Kotlin/Native compiler reads Apple headers and generates Kotlin signatures. An Objective-C class arrives as a normal Kotlin class you can construct.

Methods Map to Functions

Objective-C selectors turn into Kotlin functions. A long selector like stringWithFormat: becomes a tidy named function you call the usual way. ✨

Nullability Carries Over

Apple nullability annotations map to Kotlin types. A nullable Objective-C value becomes a Kotlin nullable type, so the compiler still guards you.

val url: NSURL? = NSURL.URLWithString("https://x.io")

Constants and Enums

Framework constants and enums come across too. An NSError domain string or an enum case is reachable straight from Kotlin code.

Versions and Availability

Bindings track an iOS SDK version. Newer Apple APIs only appear if your deployment target and SDK are recent enough to expose them.

Keep the Boundary Thin

Call Apple APIs in a small iosMain wrapper, then expose a clean Kotlin result. Hiding platform detail behind one function keeps shared code tidy.

Quick Check

A quick one on where Apple framework calls belong.

Recap: Apple from Kotlin

You saw that Kotlin/Native exposes Apple frameworks under platform packages, callable from iosMain with familiar Kotlin syntax. Keep them behind a thin wrapper. 🎉

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

هل درس «استخدام أطر Apple من Kotlin» مجاني؟

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

ماذا ستتعلم في «استخدام أطر Apple من Kotlin»؟

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

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

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

كم من الوقت يستغرق درس «استخدام أطر Apple من Kotlin»؟

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

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

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

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

  1. استخدام أطر Apple من Kotlin
  2. الذاكرة وARC في Kotlin/Native
  3. التكامل البيني مع مكتبات C
  4. تغليف Native SDK بطريقة نظيفة
← العودة إلى Kotlin Multiplatform Academy