expect/actual Neden Var
Tek bir API'nin arkasındaki platforma özgü davranış mekanizmasını öğrenin.
expect/actual Neden Var, CoddyKit'te ücretsiz bir Kotlin Multiplatform Academy dersidir. Bu, 4 dersinin 1. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, Kotlin Multiplatform Academy öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Kotlin Multiplatform Academy kursu toplamda 4 dersten oluşur.
Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.
One Codebase, Different Worlds
Most of your Kotlin runs everywhere, but some tasks need each platform's own tools. That gap is exactly what expect/actual was built to close.
The Problem It Solves
Getting the OS version, a file path, or current time relies on Android or iOS APIs that simply do not exist in shared code. You still want to call them from commonMain. 🤔
A Promise and a Fulfillment
Think of expect as a promise: common code declares an API exists. Then each platform fulfills that promise with a real implementation.
The expect Declaration
In commonMain you write a declaration with no body. The expect keyword means the implementation lives elsewhere, per platform.
expect fun platformName(): StringThe actual Implementation
Each target supplies the body with actual. Android returns one value, iOS returns another, but the signature must match exactly.
actual fun platformName(): String = "Android"Common Code Stays Common
Your shared logic just calls the function and never sees the difference. The compiler picks the right actual for each build.
val label = "Running on " + platformName()Not the Same as an Interface
An interface needs an object to implement it at runtime. expect/actual is resolved at compile time, so there is zero runtime cost.
Where Each Piece Lives
The expect goes in commonMain. Every actual lives in its matching source set, like androidMain or iosMain, side by side.
Every Target Must Answer
If you ship to Android and iOS, both need an actual. A missing one is a compile error, not a surprise crash later.
Use It Sparingly
Reach for expect/actual only for the thin layer that truly differs. The more code stays in common, the more you share. ✨
A Bridge, Not a Wall
expect/actual is a clean bridge to native power without splitting your project. You keep one API while each platform speaks its own language.
Quick Check
Let's make sure the core idea landed.
Recap
You learned why expect/actual exists: it lets common code call platform-specific behavior through one API, resolved at compile time with no runtime cost. 🎉
Sıkça Sorulan Sorular
“expect/actual Neden Var” dersi ücretsiz mi?
Evet — “expect/actual Neden Var” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve Kotlin Multiplatform Academy kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Kotlin Multiplatform Academy kursu toplamda 4 dersten oluşur.
“expect/actual Neden Var” dersinde ne öğreneceğim?
Tek bir API'nin arkasındaki platforma özgü davranış mekanizmasını öğrenin. Kotlin Multiplatform Academy ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.
Kotlin Multiplatform Academy öğrenmeye başlamak için deneyim gerekli mi?
Önceden deneyim gerekmez. CoddyKit'te Kotlin Multiplatform Academy, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 1. dersidir.
“expect/actual Neden Var” dersi ne kadar sürer?
Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.
Bu Kotlin Multiplatform Academy dersinde kod yazıp çalıştırabilir miyim?
Evet. Her Kotlin Multiplatform Academy dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.
Bu kursun tüm dersleri
- expect/actual Neden Var
- Her Hedef için Platform Adını Alma
- expect/actual Sınıfları ve Özellikleri
- Yaygın Hatalar ve Derleyici Hataları