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()
}Content copied to clipboard
Platform differences
Each row shows toString(), which is name, then osVersion, then deviceModel in parentheses.
| Target | Example |
|---|---|
| Android | Android 15 (API 35) (Google Pixel 8) |
| JVM | JVM Mac OS X 15.3 (aarch64): the model is the CPU architecture |
| iOS | iOS 17.4 (iPhone15,3): the simulator reports the simulated device |
| macOS | macOS 15.3.1 (Mac14,2) |
| JS, Wasm in Node | Wasm Node v22.11.0 (darwin arm64) |
| JS, Wasm in a browser | JS <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.