Platform

class Platform

Where the code runs: the OS name, the OS version, the device model and a family to branch on.

Get it from Platform.current. The class has no public constructor.

Example

println(Platform.current)   // "iOS 17.4 (iPhone15,3)"

when (Platform.current.family) {
PlatformFamily.IOS, PlatformFamily.MACOS -> useApplePath()
else -> useDefaultPath()
}

Platform differences

Each row shows toString(), which is name, then osVersion, then deviceModel in parentheses.

TargetExample
AndroidAndroid 15 (API 35) (Google Pixel 8)
JVMJVM Mac OS X 15.3 (aarch64): the model is the CPU architecture
iOSiOS 17.4 (iPhone15,3): the simulator reports the simulated device
macOSmacOS 15.3.1 (Mac14,2)
JS, Wasm in NodeWasm Node v22.11.0 (darwin arm64)
JS, Wasm in a browserJS <user agent> (macOS)

Watch out

  • The strings come from the host and can be empty. Show them in logs and bug reports, but do not parse them. Use family in code.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

The device or hardware model as the host reports it, or empty. For display only.

Link copied to clipboard

The platform kind. Use it for when branches.

Link copied to clipboard

The OS name: "Android", "JVM", "iOS", "macOS", "JS" or "Wasm".

Link copied to clipboard

The OS version as the host reports it, or empty. For display only.

Functions

Link copied to clipboard
open override fun toString(): String

"name osVersion (deviceModel)", without the parts that are empty.