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

ElliotSknr

12/12/2023, 12:34 PM
In my commonMain module I have a method to refresh some data from within a suspending context. Setting this method within android is straight forward as the suspending context is recognised, but when attempting to assign the variable from within Swift I'm facing issues as it's unable to map itself from a Kotlin Suspending function to a async function.
Copy code
var refreshSomeDataClass: suspend () -> SomeDataClass? = {
    null
}
Instead it is mapped to a 'any KotlinSuspendFunction0' which I can't simply assign to The error reads: "Cannot assign value of type '() async -> any KotlinSuspendFunction0' to type 'any KotlinSuspendFunction0'" Does anyone know how this can be achieved?
a

Andreas Dybdahl

12/12/2023, 12:43 PM
@ElliotSknr I can't say if it will be able to alleviate your specific problem, but in general when you want to be able to use Flows and Coroutines from Swift code, you will need to use either the SKIE plugin or the KMPNativeCoroutines plugin
e

ElliotSknr

12/12/2023, 1:01 PM
I have the SKIE plugin installed, with none of the features disabled, but it doesn't seem to assist with any of the interop problems here unfortunately.
a

Andreas Dybdahl

12/13/2023, 6:23 AM
@ElliotSknr have you tried by using a named function instead of a lambda in a variable? Maybe that does a difference 🤞