Hi! We are using <KMP-Native-Coroutines> and we h...
# multiplatform
a
Hi! We are using KMP-Native-Coroutines and we have some issues. As soon as we try to add some
suspend
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:
Copy code
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? đŸ€”
r
Hi! At the moment KMP-NativeCoroutines doesn’t really support Swift to Kotlin cases. Though such cases will be supported in a future version 🙂: https://github.com/rickclephas/KMP-NativeCoroutines/issues/42 Looking at the screenshot there seems to be another problem. Only the last function (the one ending with
Native
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?
a
Hi! Thanks for your rapid reply! As said, notating those methods in interface as
@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 đŸ€”
r
Hmm alright that is weird. Will definitely take a look at that.
a
Thank you! And amazing lib so far, keep it up đŸ’Ș For now I’ll use @NativeCoroutinesIgnore and update once new version is out. If you need any additional info for reproducing that issue, please let me know. Thank you!
đŸ‘đŸ» 1
r
Hi. Just did some testing and this seems like an Xcode bug as I am able to reproduce this with and without the ignore annotation. Kotlin:
Copy code
interface TestInterface {
    @NativeCoroutinesIgnore
    suspend fun refreshTokenIfNeeded(accessToken: String)
}
Swift:
Copy code
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:
Copy code
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 selector
However 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.