Niklas
11/28/2023, 12:47 PM// Kotlin
interface LoginProvider {
suspend fun login()
}
// Kotlin
class AndroidLoginProvider: LoginProvider {
override suspend fun login() { }
}
// Swift
class IOSLoginProvider: LoginProvider {
@MainActor
func login() async { }
}
// Kotlin
class AuthenticationRepository {
[...]
fun login() = withContext(Dispatchers.IO) {
loginProvider.login()
}
}
In the KMP documentation, I only find a clear indication that async/await usage is experimental when suspend functions are called from swift (see https://kotlinlang.org/docs/native-objc-interop.html#suspending-functions). However, this is not the case when a suspend function is implemented via an interface.
Also this article https://www.jetbrains.com/help/kotlin-multiplatform-dev/multiplatform-connect-to-apis.html describes only how to implement such apis in the iOS source set in shared.
If anyone can provide me with further information or sources, I would be very grateful. Thank you :)John O'Reilly
11/28/2023, 12:53 PMNiklas
11/28/2023, 12:55 PMJeff Lockhart
11/28/2023, 4:44 PMNiklas
11/28/2023, 5:01 PMJeff Lockhart
11/28/2023, 7:41 PMPiotr Prus
01/17/2024, 5:39 AMfun initShared(
getToken: suspend () -> String
)
but it doesnt convert nicely in Swift