Call Shared Code from the iOS App
Import the framework and call it from Swift.
Call Shared Code from the iOS App is a free Kotlin Multiplatform Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Kotlin Multiplatform Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
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 SharedKotlin 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. 🎉
Frequently asked questions
Is the “Call Shared Code from the iOS App” lesson free?
Yes — the full text of “Call Shared Code from the iOS App” is free to read here on the web, and the Kotlin Multiplatform Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Kotlin Multiplatform Academy course, upgrade to CoddyKit PRO.
What will I learn in “Call Shared Code from the iOS App”?
Import the framework and call it from Swift. You practise Kotlin Multiplatform Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Kotlin Multiplatform Academy?
No prior experience is required. Kotlin Multiplatform Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Call Shared Code from the iOS App” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Kotlin Multiplatform Academy lesson?
Yes. Every Kotlin Multiplatform Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- A Greeting Function in commonMain
- Call Shared Code from the Android App
- Call Shared Code from the iOS App
- Change Once, See It on Both Apps