I have a Kotlin multi-platform project with two targets: Android and iOS. I'm trying to expose a JVM-like String.format function in my common code
expect fun format(format: String, vararg params: Any?)
On the Android side, I can simply use
actual fun format(format: String, vararg params: Any?) {
return if(params.isEmpty()) {
format
} else {
java.lang.String.format(Locale.getDefault(), format, *params)
}
}
However, on the iOS side, using the equivalent approach
actual fun format(format: String, vararg params: Any?) {
return if(params.isEmpty()) {
format
} else {
NSString.stringWithFormat(format, *params)
}
}
results in a compiler error:
When calling variadic Objective-C methods spread operator is supported only for *arrayOf(...)
I found and read this issue on the Kotlin/Native Github but this seems to only solve calls with explicit parameters.
So how can I pass vararg parameters along to Objective-C functions? Or is it really impossible? Seems like I'm missing something obvious.
