Use Apple Frameworks from Kotlin
Access platform.Foundation and friends directly.
Use Apple Frameworks from Kotlin is a free Kotlin Multiplatform Academy lesson on CoddyKit — lesson 1 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.
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.UIDeviceA 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. 🎉
Frequently asked questions
Is the “Use Apple Frameworks from Kotlin” lesson free?
Yes — the full text of “Use Apple Frameworks from Kotlin” 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 “Use Apple Frameworks from Kotlin”?
Access platform.Foundation and friends directly. 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 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Use Apple Frameworks from Kotlin” 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
- Use Apple Frameworks from Kotlin
- Memory & ARC in Kotlin/Native
- cinterop with C Libraries
- Wrap a Native SDK Cleanly