Is there an easier way to conditionalize Kotlin co...
# multiplatform
c
Is there an easier way to conditionalize Kotlin code on iOS simulator versus device other than different source sets?
p
You can work with expect / actual
If you want to stay in commonMain land you could write an expect val isSimulator and handle the various code paths there
Or you directly have expect actual functions that no-op in different source sets
c
Yeah, that is what I ended up doing (expect / actual with different source sets), it’s just annoying to have to split it up among several different files
p
So my suggestion fixes that?
c
The alternative would be something like a precompiler, which makes code difficult to read and test, which is why Kotlin doesn’t use a one. For simple variables, something like this might help bridge the gap, though I’m not how to use to it for different values per KMPP sourceset https://github.com/gmazzo/gradle-buildconfig-plugin
p
I wonder what these specifics are. We have approx 40k loc multiplatform and only a handful of expect actual stuff
c
I was about to say that BuildConfig like system would achieve what I want (runtime branching against a compile time constant) my branching is not between one branch that compiles and one that does not at the moment, it just changing some logic
I could imagine annotations built with KSP to exclude classes from a build or branch at compile time based on certain options
p
But why not a simple
expect val isSimulator
The you can just do a if(isSimulator) doStuff else doOtherStuff