hi, I am trying to export some Swift code from my ...
# touchlab-tools
a
hi, I am trying to export some Swift code from my
iosMain/swift
source set using the Swift Code Bundling feature from SKIE. The Swift code gets detected by SKIE (it is being included in the
shared/build/skie/compilation/iosSimulatorArm64/main/swift/bundled
folder), so apparently Swift Code Bundling is working. Buut, for some reason it seems that code is not being exposed because when I go to my
iosApp
I can only see the generated Swift code from Kotlin code, but nothing from the Swift files in my
iosMain/swift
folder. Any ideas? I can share more details on the setup I'm trying or any other information you think would be useful
t
Are the declarations in your Swift files explicitly using
public
visibility?
a
yes, sorry, I forgot to mention that... I am exposing a struct (that is a SwiftUI view actually, is a wrapper around some Compose Multiplatform code) and 1 extension function... the extension function seems that is being exposed as transformed Swift code, because it is being exposed under a
ExtensionsKt
class, which is wrong, because I have an
Extensions.swift
file declared for that extension
t
Is the swift in a dependency module or in the module producing the framework?
a
is in the module producing the framework (the
shared
module)... I have a
composeApp
module that I use as a demo module for the functionality in the
shared
module, and the
iosApp
that consumes the
composeApp
generated XCFramework... the
composeApp
has an
api(project(":shared"))
dependency declaration in it and it also export that same
shared
dependency in the generated framework
Copy code
listOf(
    iosX64(),
    iosArm64(),
    iosSimulatorArm64()
).forEach { iosTarget ->
    iosTarget.binaries.framework {
        baseName = "ComposeApp"
        isStatic = false
        export(project(":shared"))
    }
}
t
How are you checking whether the Swift is included?
Wait I’m confused, is shared the framework or composeApp?
a
TLDR:
iosApp
->`composeApp` ->`shared` it's a transitive dependency...
iosApp
consumes the artifact generated by
composeApp
, which consumes the
shared
module. The default structure of any KMP/CMP repo that uses the
composeApp
as a demo app of the
shared
module I am trying to make a native wrapper for some Compose Multiplatform code I have... so I thought that I could use Swift Code Bundling for that. Ideally, the
shared
module should produce a distributable XCFramework to be consumed by a native iOS app. Sooo, I thought of using the
iosApp
as a client of the artifact generated by the
shared
module, buut that code is actually being consumed by the
composeApp
and the
composeApp
module is generating the final XCFramework consumed by the
iosApp
t
I see, are you applying SKIE to both
shared
and
composeApp
?
a
nop, only to the
shared
module
t
SKIE needs to be applied to modules that include the Swift code as well as the module that produces the framework that you use from Xcode
a
oooh ok... should I enable the Swift Code Bundling feature in
composeApp
too? or just applying the plugin do the trick?
t
I don't think there's an enable for Swift Code Bundling, is there?
a
there's an option to enable swift bundling in the SKIE gradle plugin
Copy code
skie {
    swiftBundling {
        enabled = true|false
    }
}
I don't know if that is still relevant though, but is there haha
t
I see, yeah it's more to disable it, it's on by default
a
cool... I'm trying what you suggested now... will report back with results after the build finishes
it worked! thank you very much @Tadeas Kriz I am facing another issue now, and that is that I have some enum classes in Kotlin that implements an interface, and those are being translated as enums in Swift but without extending that interface, so my SwiftUI wrapper (that expects a list of items that extend that interface) is giving me errors now because types doesn't match... is there an easy workaround to that or I just have to start playing around to see what can be done with that?
or maybe exclude those files from being parsed by SKIE? they were working before that, so that could be a simple solution, but I don't know if SKIE supports exclusions
t
You can use SKIE annotations to disable EnumInterop for that specific enum, or you can use the
__SomeEnum
name (two underscores)
There should be a function
toKotlinEnum()
on the Swift enum and
toSwiftEnum()
on the Kotlin one to convert between them
a
Ok! Will see which approach works best, thank you Tadeas!
Is there a way to disable SKIE only for a certain package?
a
it worked like a charm... thank you for all the help Tadeas