Apple-Frameworks aus Kotlin verwenden
Auf platform.Foundation und verwandte APIs direkt zugreifen
Apple-Frameworks aus Kotlin verwenden ist eine kostenlose Kotlin Multiplatform Academy-Lektion auf CoddyKit. Dies ist Lektion 1 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Kotlin Multiplatform Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Kotlin Multiplatform Academy-Kurs umfasst insgesamt 4 Lektionen.
Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.
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. 🎉
Häufig gestellte Fragen
Ist die Lektion „Apple-Frameworks aus Kotlin verwenden“ kostenlos?
Ja — der vollständige Text von „Apple-Frameworks aus Kotlin verwenden“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Kotlin Multiplatform Academy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Kotlin Multiplatform Academy-Kurs umfasst insgesamt 4 Lektionen.
Was lerne ich in „Apple-Frameworks aus Kotlin verwenden“?
Auf platform.Foundation und verwandte APIs direkt zugreifen Du übst Kotlin Multiplatform Academy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.
Brauche ich Erfahrung, um Kotlin Multiplatform Academy zu starten?
Keine Vorkenntnisse erforderlich. Kotlin Multiplatform Academy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 1 von 4.
Wie lange dauert die Lektion „Apple-Frameworks aus Kotlin verwenden“?
Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.
Kann ich in dieser Kotlin Multiplatform Academy-Lektion Code schreiben und ausführen?
Ja. Jede Kotlin Multiplatform Academy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.
Alle Lektionen in diesem Kurs
- Apple-Frameworks aus Kotlin verwenden
- Speicher und ARC in Kotlin/Native
- cinterop mit C-Bibliotheken
- Ein Native SDK sauber kapseln