KMP project structure
Targets, source sets and expect/actual
KMP compiles shared code for the module's configured targets. A target describes a compilation platform; a source set groups source files and dependencies. They are different concepts. Project structure.
Source sets
commonMain holds production code shared by the module's targets, and commonTest holds shared test code. Platform sets can use common code; common code cannot import an Android/JVM-only API when it must also compile for iOS. Source sets.
Intermediate sets such as iosMain share code between the applicable iOS targets. The default hierarchy template creates relevant sets from the target configuration, rather than creating every possible set unconditionally. Manual dependsOn edges can disable automatic template application. Hierarchy.
Platform boundary
// commonMain/Platform.kt
expect fun platformName(): String
// androidMain/Platform.kt
actual fun platformName(): String = "Android"
// iosMain/Platform.kt
actual fun platformName(): String = "iOS"
These are separate files in the same package. Each configured target needs a matching actual, possibly inherited through an intermediate source set. An interface with an injected implementation is another way to share a contract. Expect/actual.
For ordinary UUID generation, Kotlin 2.4.0 stabilizes the common Uuid API, including Uuid.random(); expect/actual is no longer necessary just to access that capability. Newer generateV4/generateV7 functions retain separate experimental status. Kotlin 2.4.0.
iOS integration
Choose a supported Xcode/framework integration explicitly. For an Objective-C-exported framework, suspend functions use completion handlers with an available Swift async form; Flow observation, ownership, cancellation and errors need a bridge contract. Do not assume this describes the separate Swift export mechanism. Integration, Objective-C interop.