Francis Mariano

    Francis Mariano

    1 year ago
    Hello folks. I have the following expect function
    expect fun String.formatPlatform(vararg args: Any?): String
    and on iosMain module I wrote the actual function
    actual fun String.formatPlatform(vararg args: Any?): String {
        return NSString.create(format = this, args = arrayOf(args)).toString()
    }
    But when I compile that code I get this error :
    kotlin.Array<out kotlin.Any?>  is not supported here: doesn't correspond to any C type
    I tried to change the parameter type from expect function to Float or Double, but the error continues:
    kotlin.Array<out kotlin.Float?>  is not supported here: doesn't correspond to any C type
    I read the issue https://github.com/JetBrains/kotlin-native/issues/1834 but I do not solve the problem. Can anyone help me with that? Thank you.
    louiscad

    louiscad

    1 year ago
    You at least miss the spread operator (
    *
    ). Look at this comment in the issue: https://github.com/JetBrains/kotlin-native/issues/1834#issuecomment-484854268
    Francis Mariano

    Francis Mariano

    1 year ago
    @louiscad I think so not When I add the spread operator the Android Studio show me a warning :
    Redundant spread (*) operator
    and the error is the same.
    actual fun String.formatPlatform(vararg args: Any?): String {
        return NSString.create(format = this, args = *arrayOf(args)).toString()
    }
    louiscad

    louiscad

    1 year ago
    Same issue when using
    stringWithFormat
    ?
    Francis Mariano

    Francis Mariano

    1 year ago
    Yes.
    actual fun String.formatPlatform(vararg args: Any?): String {
        return NSString.stringWithFormat(format = this, args = arrayOf(args))
    }
    type kotlin.Array<out kotlin.Any?> is not supported here: doesn't correspond to any C type
    louiscad

    louiscad

    1 year ago
    Looks like what you want is impossible, so you'll need to hardcode every time for iOS until there's a better solution.
    Francis Mariano

    Francis Mariano

    1 year ago
    yeah, I am watching that issue in youtrack. Thank you