Did anyone figure out how to use an expect/actual ...
# kotlin-native
t
Did anyone figure out how to use an expect/actual for
java.lang.String.format
and
NSString.create(format, args)
? The
NSString
requires you to use
*arrayOf(…)
for args. For example let’s say this is the expect function:
Copy code
expect fun String.format(vararg args: Any?): String
How would you able to make an actual fun using
NSString.create
?
s
How would you able to make an actual fun using
NSString.create
?
Due to restrictions of C/Objective-C varargs you can’t pass values received through Kotlin variadic parameters to Objective-C variadic method.
t
Thanks, that’s what I was afraid of. I guess I will need to avoid vararg for this, and use multiple functions for different type of arguments
I hoped something like an inline expect/actual function would work for this. So the varargs are inlined into the C method call
s
I guess I will need to avoid vararg for this, and use multiple functions for different type of arguments
This is probably the only solution for now.
t
@svyatoslav.scherbina That is what I have now done, and works fine for me. Thanks for your help.
👍 1