https://kotlinlang.org logo
Title
j

juh juh

08/18/2022, 7:33 PM
Are there runtime methods to check which platform code is running on?
l

Landry Norris

08/18/2022, 7:40 PM
Not by default. You’d have to use expect/actuals. I created a library for this https://github.com/LandryNorris/PlatformInfo
I published it to maven at io.github.landrynorris😛latform-info:1.1.0, I believe. That was kind of a one-off thing, so I don’t remember the exact version.
l

Landry Norris

08/18/2022, 7:49 PM
You learn something new every day.
Is this available on Android, or just Kotlin/Native? I don’t see it autocomplete like it does in iosMain.
j

juh juh

08/18/2022, 8:01 PM
Thanks!
j

jw

08/18/2022, 8:03 PM
the stdlib function is only for kotlin/native targets
m

Matthias Geisler

08/18/2022, 8:06 PM
You can do it via expect/actual...but the better question is why you wanna do that? You could implement the what you want in the platform source.
l

Landry Norris

08/18/2022, 8:07 PM
I’ve also seen people define a common interface, then implement it in Android and iOS, passing it via Koin.
m

Matthias Geisler

08/18/2022, 8:09 PM
I think that is the better way to go