https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
f

Francis Mariano

06/26/2021, 2:27 PM
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
Copy code
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.
l

louiscad

06/27/2021, 6:52 AM
You at least miss the spread operator (
*
). Look at this comment in the issue: https://github.com/JetBrains/kotlin-native/issues/1834#issuecomment-484854268
f

Francis Mariano

06/28/2021, 11:34 AM
@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.
Copy code
actual fun String.formatPlatform(vararg args: Any?): String {
    return NSString.create(format = this, args = *arrayOf(args)).toString()
}
l

louiscad

06/28/2021, 11:57 AM
Same issue when using
stringWithFormat
?
f

Francis Mariano

06/28/2021, 12:41 PM
Yes.
Copy code
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
l

louiscad

06/28/2021, 2:35 PM
Looks like what you want is impossible, so you'll need to hardcode every time for iOS until there's a better solution.
f

Francis Mariano

06/28/2021, 2:59 PM
yeah, I am watching that issue in youtrack. Thank you
3 Views