Does anyone know if it’s possible to get KMP lambda suspend functions working for ios?
In KMP, I want to do something like:
class ExampleClass<TRequest, TResponse> (private val suspendCall: suspend (TRequest) -> TResponse)
But in Swift/obj-c that gets compile to:
public class ExampleClass<TRequest, TResponse> : KotlinBase where TRequest : AnyObject, TResponse : AnyObject {
public init(suspendCall: any KotlinSuspendFunction1)
}
One workaround I thought of was instead of passing a lambda, I pass in an abstract class with that function, however Swift doesn’t support anonymous classes and I don’t want to have to define an explicit input class type each time I create the
ExampleClass
. I can’t use protocols here either because obj-c doesn’t support generics.
If the
suspendCall
constructor param in KMP isn’t a suspend fun, then the lambda code in Swift is generated fine, but when I add the
suspend
keyword it’s not able to generate the async/await lambda. Does anyone have any ideas how to work around this?