So maybe this is asked here already but we have an...
# multiplatform
j
So maybe this is asked here already but we have an issue. All functions in our shared code marked as
Copy code
suspend
do not show up in the compiled iOS code and cannot be called. Do we have to remove coroutine support from our shared code or is there some trick to make it work?
k
iOS has no concept of suspend. You need to pass a callback
👍 3
j
This confuses me a bit as there is a KMP library for coroutines and no compilation errors. The functions just are missing
ktor also uses coroutines to make calls.
is there a nice pattern to implement a multi-platform API that calls backend with ktor
but doesn’t use suspend in the interface
k
You can’t expose suspend methods to the iOS header. We just have the external method take a lambda and have Swift pass that in.
j
ok
but you can’t use launch{} in KMP either, as far as I figured out, or?
k
On phone right now, but can dig up a sample in a bit
j
so how can I call Ktor.
cool, thanks 🙂
k
Why can't you use launch?
j
does not compile 😕
sigh. Maybe somethign is missing
l
You can use launch and works
j
okay, must be gradle messed up then, thanks. I’ll dig into it
o
j
oh, that’s cool. Thanks!
k
Interesting. Never heard of these
j
These both look a bit old. Are they still active?
k
They’re def old. Digging a bit
j
We had an issue with older libraries that they don’t compile anymore as they were compiled by older Kotlin verison
as an idea, these look amazing
especially
Copy code
@Recast
k
Native libraries need to be updated. There look like compiler plugins, although that seems like a strange/risky place to be just now
👍 1
Got it. For “recast”, you need to use kapt to make source for iOS
j
do you feel it’s a worth a try at this stage?
k
The other one uses https://github.com/Foso/MpApt, which I’ve avoided, but see how it goes
Not even close
But that’s me
j
I’m a complete n00b stumblin in dark trying to get our lib working so I happily take in your input
k
I don’t find the callback scheme to be that difficult to implement, and I’d expect to spend more time on sorting out config
j
I’ll just write a wrapper into the repository that calls the suspend ones and responds in callbacks
k
Yeah, it’s extra “code” but not that hard to do
j
yeah, exactly. And if something breaks at least I know I did it 😄
k
I was going to send a sample, but then updated intellij, then got distracted…
j
Thanks. Much appreciate the expertise 🙂
k
What’s your github? I’ll add you to our new sample app.
j
JuhaniLehtimaeki
thanks 🙂
r
My solution is to not write any Swift code 😛
k
Added, but forgot we’re using Flow, not passing in callbacks to methods.