Alen Kirm
03/28/2022, 7:52 AMsuspend
method inside Interface
file, and conform to that file on iOS side, KMP-Native-Coroutines
generates 3 versions of that method.
Our example:
Kotlin Interface method:
suspend fun refreshTokenIfNeeded(accessToken: String)
Results into (see attachment below) on iOS and blocks us.
Are there any known issues regarding suspend
methods in signature? Did anybody else face this problem? None of the workarounds seems future proof and could bite back soon.
On modules, where KMP-Native-Coroutines
plugin is not injected, it works fine as expected.
Update:
Looks like marking method with @NativeCoroutinesIgnore
is a working workaround. Is this something worth taking a look at? đ€Rick Clephas
03/28/2022, 8:21 AMNative
is generated by the plugin). The other two functions arenât generated by the plugin.
It looks like you have both the âoldâ completion handler style and the ânewâ async one.
Which seems odd since the conversion to an async function is done by Swift (not Kotlin).
Canât you remove one of the refreshTokenIfNeeded
functions?Alen Kirm
03/28/2022, 10:18 AM@NativeCoroutinesIgnore
solves this issue perfectly. Now I can only use on (async or callback version) and there is no more native
one as plugin is disabled.
Will have to figure out why both (async and callback) are generated. Strange this is, that as soon as I remove @NativeCoroutinesIgnore
notation, compiler starts to complain I need to implement both versions of that method đ€Rick Clephas
03/28/2022, 10:57 AMAlen Kirm
03/28/2022, 10:59 AMRick Clephas
03/28/2022, 4:17 PMinterface TestInterface {
@NativeCoroutinesIgnore
suspend fun refreshTokenIfNeeded(accessToken: String)
}
Swift:
class TestImpl: TestInterface {
}
This will fail with
Type âTestImplâ does not conform to protocol âTestInterfaceâ
Do you want to add protocol stubs?Clicking on fix generates the following functions:
func refreshTokenIfNeeded(accessToken: String, completionHandler: @escaping (KotlinUnit?, Error?) -> Void) {
<#code#>
}
func refreshTokenIfNeeded(accessToken: String) async throws -> KotlinUnit {
<#code#>
}
Which will fail with:
Method ârefreshTokenIfNeeded(accessToken:)â with Objective-C selector ârefreshTokenIfNeededAccessTokencompletionHandlerâ conflicts with method ârefreshTokenIfNeeded(accessTokencompletionHandler)â with the same Objective-C selectorHowever after removing
refreshTokenIfNeeded(accessToken:completionHandler:)
(and returning KotlinUnit.shared
in the other function) the code does compile.
FYI this only seems to occur if none of the functions are added. As soon as you already have a single function the âfixâ action wonât add the duplicate function.