Is this available in some Kotlin dev version? - <...
# swift-export
j
j
fwiw this is the youtrack issue I'm tracking for this https://youtrack.jetbrains.com/issue/KT-80305
thank you color 2
j
The dev versions are listed by GitHub on the link you sent
It's available in 71 of them
j
@jw I cannot see them (I am on GitHub mobile) 🤔
j
You can share to browser and see on mobile
j
Found, thank you 🙏
I get it “working”, the codegen includes the async func but it is not compatible due not using a version above 13 for iOS. I have changed everything on XCode to iOS 26, do I need to change it with some compiler arg in Kotlin?
j
I've been trying out dev builds as well and now seeing following error when building in Xcode if I expose suspend function
Copy code
iosSimulatorArm64/Debug/Sources/Shared/Shared.swift:347:26 contextual closure type '() -> Void' expects 0 arguments, but 1 was used in closure body
🫠 1
g
which version? I’m using
-5897
-
9111
was failing -, and I don’t see async functions being generated, example:
Copy code
suspend fun testSuspendFunction(): String {
    return "Hello from suspend function"
}

suspend fun testSuspendFunction2(): Flow<String> {
    return flow { "Hello from suspend function" }
}
are ignored.
ok with
9149
they are generated:
Copy code
public static func testSuspendFunction() async -> Swift.String {
            await withUnsafeContinuation { nativeContinuation in
                let continuation: (Swift.String) -> Swift.Void = { nativeContinuation.resume(returning: $0) }
                let _: () = com_sample_models_testSuspendFunction({
        let originalBlock = continuation
        return { arg0 in return originalBlock(arg0) }
    }())
            }
}
public static func testSuspendFunction2() async -> any ExportedKotlinPackages.kotlinx.coroutines.flow.Flow {
            await withUnsafeContinuation { nativeContinuation in
                let continuation: (any ExportedKotlinPackages.kotlinx.coroutines.flow.Flow) -> Swift.Void = { nativeContinuation.resume(returning: $0) }
                let _: () = com_sample_models_testSuspendFunction2({
        let originalBlock = continuation
        return { arg0 in return originalBlock(KotlinRuntime.KotlinBase.__createProtocolWrapper(externalRCRef: arg0) as! any ExportedKotlinPackages.kotlinx.coroutines.flow.Flow) }
    }())
            }
}
Although (using xcode 26, swift 6 and targeting iOS26):
j
@John O'Reilly didn’t you get the iOS 13 error?
I had Swift 5, so probably, if I use 6 I would get the rest of errors @Guilherme Delgado is showing
j
so, using https://github.com/joreilly/chip-8 to test (that project was updated already to use Swift Export).....added suspend function locally in shared code and updated to
2.3.0-dev-9149
and still seeing error above. Using Xcode 26 and Swift 6.
fwiw have included updates to use latest versions in this branch https://github.com/joreilly/chip-8/tree/swift_export
j
This branch is 161 commits ahead of, 2 commits behind cbeust/chip-8:master
I think you need to change the base branch?\
j
no, that's from original project I forked this from....it's diverged considerably since then
this shows those last differences more clearly https://github.com/joreilly/chip-8/pull/60
still getting that
contextual closure type '() -> Void' expects 0 arguments, but 1 was used in closure body
error ....but I might have missed something I need to update
g
I’ve tried to replicate with the most simple project possible (the one I was using is multimodule), and for that I’ve used the Wizard. And I found out this:
Never saw this in my other projects. Although, it fails with the same output shared above.
j
What dev version are you currently using?
g
2.3.0-dev-9149
a
Hello everyone 🙂 We do appreciate that you are all excited to try out Coroutines support in Swift Export. Just a heads up. Support for coroutines will not be ready in 2.3.0. And in order to not break current export - we have to introduce a feature flag for coroutines support. One can find a rough example of how this flag can be enabled here. Current limited support should become usable on Xcode projects after https://youtrack.jetbrains.com/issue/KT-81465. Have fun experimenting!
👍 1
g
I guess
2.3.0-Beta1
has that flag enabled by default — I was testing it a moment ago and everything built successfully, but the coroutines code got ignored 😅 Thanks for the heads-up!
a
2.3.0-Beta1 did not had that flag at all, it was merged in master only today 🙂
g
OK, well, the exported code skipped the:
Copy code
suspend fun testSuspendFunction(): String {
    return "Hello from suspend function"
}

suspend fun testSuspendFunction2(): Flow<String> {
    return flow { "Hello from suspend function" }
}
But anyway, nice to have that flag 🙂
a
Copy code
contextual closure type '() -> Void' expects 0 arguments, but 1 was used in closure body
KT-81593 Swift Export: suspend function returning Unit leads to incompilable code We have discovered the root cause for that error. Thanks for the report!
👍 2
j
Haven’t have time to recheck commits. Something new around Flow?
a
Something new around Flow?
Currently we do not work towards supporting
Flow
, all current work is dedicated to supporting actual suspend functions.
thank you color 1
👍 1
j
The only workaround for now is creating callbacks in Kotlin to consume them on Swift as nothing related to Flow is generated in Swift, right?
👍 1
a
is creating callbacks in Kotlin to consume them on Swift
Nope, producing functional types from kotlin into swift is also not supported, only the other way around 🙂
(but if you mean the other way around - then yes, you can workaround like that)
j
Do you know more or less an ETA about Flow support in a dev build? Can it be Q1 next year or too ambitious?
a
Nope, we do not have a public timeline for that feature 🙂
👍 1