https://kotlinlang.org logo
j

Juhani Lehtimäki

01/24/2020, 2:57 PM
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

kpgalligan

01/24/2020, 3:08 PM
iOS has no concept of suspend. You need to pass a callback
👍 3
j

Juhani Lehtimäki

01/24/2020, 3:08 PM
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

kpgalligan

01/24/2020, 3:10 PM
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

Juhani Lehtimäki

01/24/2020, 3:11 PM
ok
but you can’t use launch{} in KMP either, as far as I figured out, or?
k

kpgalligan

01/24/2020, 3:11 PM
On phone right now, but can dig up a sample in a bit
j

Juhani Lehtimäki

01/24/2020, 3:11 PM
so how can I call Ktor.
cool, thanks 🙂
k

kpgalligan

01/24/2020, 3:11 PM
Why can't you use launch?
j

Juhani Lehtimäki

01/24/2020, 3:11 PM
does not compile 😕
sigh. Maybe somethign is missing
l

Larten

01/24/2020, 3:12 PM
You can use launch and works
j

Juhani Lehtimäki

01/24/2020, 3:13 PM
okay, must be gradle messed up then, thanks. I’ll dig into it
o

Olenyov Kirill

01/24/2020, 3:28 PM
j

Juhani Lehtimäki

01/24/2020, 3:29 PM
oh, that’s cool. Thanks!
k

kpgalligan

01/24/2020, 3:30 PM
Interesting. Never heard of these
j

Juhani Lehtimäki

01/24/2020, 3:30 PM
These both look a bit old. Are they still active?
k

kpgalligan

01/24/2020, 3:30 PM
They’re def old. Digging a bit
j

Juhani Lehtimäki

01/24/2020, 3:31 PM
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

kpgalligan

01/24/2020, 3:31 PM
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

Juhani Lehtimäki

01/24/2020, 3:33 PM
do you feel it’s a worth a try at this stage?
k

kpgalligan

01/24/2020, 3:33 PM
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

Juhani Lehtimäki

01/24/2020, 3:34 PM
I’m a complete n00b stumblin in dark trying to get our lib working so I happily take in your input
k

kpgalligan

01/24/2020, 3:34 PM
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

Juhani Lehtimäki

01/24/2020, 3:34 PM
I’ll just write a wrapper into the repository that calls the suspend ones and responds in callbacks
k

kpgalligan

01/24/2020, 3:34 PM
Yeah, it’s extra “code” but not that hard to do
j

Juhani Lehtimäki

01/24/2020, 3:35 PM
yeah, exactly. And if something breaks at least I know I did it 😄
k

kpgalligan

01/24/2020, 3:35 PM
I was going to send a sample, but then updated intellij, then got distracted…
j

Juhani Lehtimäki

01/24/2020, 3:35 PM
Thanks. Much appreciate the expertise 🙂
k

kpgalligan

01/24/2020, 3:35 PM
What’s your github? I’ll add you to our new sample app.
j

Juhani Lehtimäki

01/24/2020, 3:36 PM
JuhaniLehtimaeki
thanks 🙂
r

ribesg

01/24/2020, 3:36 PM
My solution is to not write any Swift code 😛
k

kpgalligan

01/24/2020, 3:38 PM
Added, but forgot we’re using Flow, not passing in callbacks to methods.