0Pricing
Kotlin Multiplatform Academy · درس

استدعاء التعليمات البرمجية المشتركة من تطبيق iOS

استيراد الإطار واستدعاؤه من Swift

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

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

Shared Code as a Framework

On iOS your Kotlin compiles into a framework. Swift consumes it just like any Apple library you import into a project.

Import the Framework

At the top of your Swift file you import the shared framework by its name, usually Shared. That single line unlocks every export.

import Shared

Kotlin Becomes Swift

The Kotlin compiler exposes your function through an Objective-C header. Swift then sees it as a clean, native-looking call.

Top-Level Goes in a Helper

Top-level Kotlin functions land on a generated Kt helper class. You call greet through that container from Swift.

let message = GreetingKt.greet(name: "iOS")

Named Arguments

Swift turns the Kotlin parameter into a named argument. That is why you write name: when you call into shared code.

GreetingKt.greet(name: "iOS")

Show It in SwiftUI

Drop the returned String straight into a Text view. SwiftUI renders the greeting your shared Kotlin produced. 🍎

Text(GreetingKt.greet(name: "iOS"))

Strings Map Cleanly

A Kotlin String arrives as a Swift String automatically. Simple types cross the boundary without any manual conversion.

Link the Framework

Xcode links the framework through a build phase the wizard set up. As long as that phase runs, the import resolves.

Build From Xcode

Press Run in Xcode and choose a simulator. The greeting appears, proving Swift reached all the way into your Kotlin.

When Swift Cannot See It

If the import is red, the framework likely was not rebuilt. Build the shared module so Xcode picks up the latest header.

Same Logic, New Host

iOS wrote no greeting logic either. It is purely a consumer of the exact code Android already used.

Quick Check

How does Swift access a top-level Kotlin function?

Recap

You imported the shared framework, called greet through its Kt helper with a named argument, and rendered it in SwiftUI. 🎉

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

هل درس «استدعاء التعليمات البرمجية المشتركة من تطبيق iOS» مجاني؟

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

ماذا ستتعلم في «استدعاء التعليمات البرمجية المشتركة من تطبيق iOS»؟

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

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

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

كم من الوقت يستغرق درس «استدعاء التعليمات البرمجية المشتركة من تطبيق iOS»؟

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

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

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

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

  1. دالة ترحيب في commonMain
  2. استدعاء التعليمات البرمجية المشتركة من تطبيق Android
  3. استدعاء التعليمات البرمجية المشتركة من تطبيق iOS
  4. غيّر مرة واحدة وشاهد النتيجة في التطبيقين
← العودة إلى Kotlin Multiplatform Academy