Kotlin Tutorial

Kotlin Multiplatform (KMP)

Sharing code across iOS, Android, Web, and Desktop.

Sharing Logic, Not UI

Kotlin Multiplatform allows you to share your business logic (data models, networking, validation) across all platforms while keeping the native UI layers (SwiftUI, Jetpack Compose).

The Expect/Actual Pattern

KMP uses the expect and actual keywords to handle platform-specific implementations.
kotlin
// Common module
expect fun getPlatformName(): String

// iOS module
actual fun getPlatformName(): String = "iOS"

// Android module
actual fun getPlatformName(): String = "Android"

Key Ecosystem Components

ComponentPurpose
KtorMultiplatform networking client.
Kotlin SerializationCross-platform JSON parsing.
SQLDelightCross-platform local database.
Compose MultiplatformShared UI framework (experimental for some platforms).

Summary Table

FeatureAdvantage
ConsistencyOne business logic implementation.
PerformanceCompiles to native code (no bridge like React Native).
FlexibilityMix and match common and platform-specific code.