Kotlin & Coroutines (50 Qs)•Part 3: K2 Compiler, KMP, Advanced Metaprogramming & Optimization (25 - 35)
Kotlin Multiplatform (KMP): `expect`/`actual` declarations and shared architecture across iOS and Android.
senior LevelCode ExampleFormsPerformanceSystem Design
In Simple Words: KMP allows compiling pure Kotlin business logic (networking, local databases, ViewModels, analytics) to native code across iOS and Android:
- Shared Code (
commonMain): Standard Kotlin code shared across all targets. - Platform Bridging (
expect/actual):kotlin// commonMain expect fun getPlatformName(): String // androidMain actual fun getPlatformName(): String = "Android ${Build.VERSION.SDK_INT}" // iosMain actual fun getPlatformName(): String = UIDevice.currentDevice.systemName() - Compiles into native
.aarfor Android and native Apple.xcframeworkfor iOS with zero runtime bridge overhead.