Skip to content
Commitwise
Menu

expect and actual (Kotlin Multiplatform)

A Kotlin Multiplatform mechanism: common code declares an API with expect, and each platform provides it with actual.

Definition

The compiler checks that every target has an actual declaration for each expect. It suits small platform primitives such as an HTTP engine or a UUID generator; larger capabilities are often simpler as interfaces in common code, implemented and injected by each app.

In practice

expect fun httpEngine() in commonMain; actual implementations return OkHttp on Android and Darwin on iOS.

Learn it in context

Lessons that use this term.

Related terms

Esc

Type to search the whole site.