I have an interface described in kotlin: ```interf...
# kotlin-native
j
I have an interface described in kotlin:
Copy code
interface Transport {
    suspend fun <T : Any> send(command: Command<T>, data: String): String
}
but when generated ios framework, there is no such method generated:
Copy code
__attribute__((swift_name("Transport")))
@protocol IosTransport
@required
@end;
what’s wrong?
s
suspend
functions aren’t exposed to Objective-C and Swift.
j
so in a multiplatform (ios/jvm) framework you can’t use them?
are there any workarounds for this? As we already have quite a big lib that uses a lot of suspend functions 😞
t
You cannot consume suspend from iOS because there is no coroutines in iOS
Create blocking/async wrapper for it
j
so basically I have to remove all suspend’s from method signatures and handle that stuff inside methods? Or is it possible to make somthing similar to what is decribed here for java? https://stackoverflow.com/questions/51808992/kotlin-suspend-fun
s
so basically I have to remove all suspend’s from method signatures
This is required only for interfaces and classes you subclass in Swift or Objective-C.
Or is it possible to make somthing similar to what is decribed here for java?
No.
j
thanks!
s
You can make a parallel method that accepts a completion block and wraps your suspend method. It’s not very pretty but it works. Here’s an example. https://github.com/samus/mpp_chuck_demo/blob/master/app/src/commonMain/kotlin/com/synappticlabs/chuck/network/JokeApiClient.kt#L39
👍 1