0

Straight from the Kotlin Multiplatform for iOS and Android tutorial I have a template source file for iOS code which looks like this:

class IOSPlatform: Platform {
    override val name: String = UIDevice.currentDevice.systemName() + " " + UIDevice.currentDevice.systemVersion
}

actual fun getPlatform(): Platform = IOSPlatform()

Now I would like to change the value of the name override using iOS #if/#else/#endif code mechanism. In typical kotlin fashion I would write something like this for the android platform:

class IOSPlatform : Platform {
    override val name: String
        get() {
            if (BuildConfig.DEBUG) {
                return UIDevice.currentDevice.systemName() + " debug " + UIDevice.currentDevice.systemVersion
            } else {
                return UIDevice.currentDevice.systemName() + " release " + UIDevice.currentDevice.systemVersion
            }
        }
}

However, there is no BuildConfig equivalent for iOS, and obviously I can't write #if DEBUG in Kotlin like I would in Swift. Is my only option to call a custom Swift implementation where the #if conditional is implemented in a .swift source file?

Grzegorz Adam Hankiewicz
  • 7,349
  • 1
  • 36
  • 78
  • Does this answer your question? [How to determine build type in kotlin-multiplatform project](https://stackoverflow.com/questions/54255368/how-to-determine-build-type-in-kotlin-multiplatform-project) – Phil Dukhov Feb 20 '23 at 14:14
  • @PhilDukhov the example is the same because it's the easiest minimal code, but I guess the answer is it's impossible to write preprocessor code in kotlin. – Grzegorz Adam Hankiewicz Feb 21 '23 at 08:41
  • well yes, there's no such thing in kotlin. I guess `Platform.isDebugBinary` is using it under the hood – Phil Dukhov Feb 21 '23 at 09:36

0 Answers0