https://kotlinlang.org logo
Join Slack
Powered by
# swift-export
  • j

    John O'Reilly

    06/19/2024, 5:24 PM
    Should https://github.com/Kotlin/swift-export-sample work with new Kotlin 2.0.20-Beta1 version? Getting following when building in Xcode using that version
    Copy code
    Showing Recent Issues
    > Could not resolve all files for configuration ':shared:swiftExportClasspathResolvable'.
    
       > Could not find org.jetbrains.kotlin:swift-export-embeddable:2.0.20-Beta1.
    m
    s
    • 3
    • 2
  • s

    sergey.bogolepov

    07/05/2024, 10:37 AM
    Hi folks and sorry for the long silence! Here is what is going on with Swift export lately: We are actively working on multi-module export and are getting closer and closer to finishing the first implementation. • In the meantime, you can watch a

    recording▾

    of a talk from Pamela Hill where she shares our ideas on this challenging topic. • A first version of DSL for Swift export in the Kotlin Gradle Plugin is also in the works: ◦ It may be rather clunky, limited, and close to Objective-C one. Which is fine, because getting things right the first time is always hard 🫠 ◦ So we will need your feedback to gradually improve it into a first-class experience 🤌 We are also working on supporting more basic types: •
    Kotlin.Nothing
    is translated to
    Swift.Never
    ✅ •
    Kotlin.Any
    is translated to a special
    KotlinBase
    (partially merged, there is still a few cases left to cover). • Support for
    Kotlin.Char
    is WIP👷‍♂️ • Support for
    Kotlin.String
    is WIP👷‍♂️ Note that these updates are not yet available on the Kotlin Playground: • The first version was implemented quickly and kinda dirty before KotlinConf and we need to make some adjustments to streamline the Playground update process 🙃 Yeah, I know this is not the most exciting status update in the world, but bear with me: fun things are coming :)
    ❤️ 31
    a
    • 2
    • 1
  • p

    Peter Tran

    08/13/2024, 10:18 PM
    Hi @sergey.bogolepov, thank you for the Swift Export update... the focus on improving dev experience and KMP adoption is very much appreciated! Question: Do you know if there is a similar initiative at JetBrains on the Windows/C#/.NET side of things? I just started to read the docs on Swift Export Architecture and Analysis API, and I imagine a similar pattern could be used to export a .NET Assembly, perhaps using mono/CppSharp and C++/CLI to help with bridging.
    s
    • 2
    • 3
  • x

    xiaobailong24

    08/14/2024, 5:35 PM
    📌
  • a

    Alexander af Trolle

    08/20/2024, 6:29 PM
    Hi, Thanks for updating the swift export kotlin sample! Is it possible combine the XCFramework builder with the SwiftExportExtension?
    s
    • 2
    • 1
  • s

    Sanjeeviraj M

    09/26/2024, 1:09 PM
    https://github.com/swiftlang/swift-java Will this make kotlin interop easier?
    👀 2
    f
    j
    +2
    • 5
    • 9
  • d

    darkmoon_uk

    10/01/2024, 1:29 AM
    Curious to get a show of hands here; but in my 3 most recent Kotlin Multiplatform projects featuring iOS; the only Swift Interop challenge I face is Importing Swift-only API's to Kotlin, and not Exporting Kotlin to Swift, as was prioritised on the roadmap 🤔 While K Compose Multiplatform is certainly not the only way to use KMP, as a major part of the ecosystem it promotes minimising the amount of Swift in the whole project and maximising Kotlin - that would indicate import-first as priority. ❗ More critically, the new iOS API's are Swift only which means I've had to write a significant number of ObC/Swift wrappers to use the features I need in KMP. This is tolerable - but only just in some cases 🥴 - and does beg the question: Why did KMP team focus on Export over Import, where only Import has ever been an issue for me - is it a technically necessary first step? More achievable? Or is my 'import case' the unusual one (finding this hard to believe) alphabet white question As a repeated Kotlin/iOS user, I'd like to understand if/when we can expect direct Swift *Import*; which seems far more valuable than Export to me. To be specific:
    ProximityReader
    ,
    FamilyControls
    and
    DeviceActivityMonitor
    have been the newer, Swift-only API's I've needed to wrap. Thread in Slack Conversation
    🙌 5
    ☝️ 4
  • s

    sergey.bogolepov

    10/25/2024, 6:43 PM
    Once again, it's been a while since the last update. Let me share with you what we accomplished in September and October. It's Friday evening, so I'm going to be brief 🙃 Open and Abstract Classes. We have finally completed all the necessary parts, and now the Liskov substitution principle is working at the interop border. Yay! Nullability.
    T?
    in Kotlin becomes
    T?
    in Swift. Interestingly, even in this relatively "obvious" case, there was a tricky issue around translating
    Nothing?
    to
    Never?
    :) List, Map, Set. We decided not to reinvent the wheel here. Under the hood, the Swift export reuses existing nice Objective-C export machinery. Thanks to Objective-C - Swift interop, these
    NS*
    collections are bridged to the corresponding Swift collections.
    @Deprecated
    .
    As I mentioned in the last post, this was a tricky topic due to multiple differences between
    @Deprecated
    and
    @available
    , but it seems we found and implemented a more or less consistent solution. What's next? Enums and Sealed Classes. As with many other features, we are starting with the most straightforward solution. Enums and sealed classes will be translated to Swift classes instead of enums, providing a user experience similar to vanilla Objective-C export, which is somewhat "meh". However, it is important for us to lay down a foundation that we can use to make Swift export more Swift-like in the future. Extensions. We are taking a conservative approach here as well, initially exporting the extension receiver as the first parameter of a function (similar to how Kotlin extensions are exported to Java). Why? Consider the following example Kotlin code:
    Copy code
    class A
    class B : A()
    
    fun A.foo() = print("a")
    fun B.foo() = print("b")
    
    val a: A = B()
    a.foo() // Outputs: "a" because of static dispatch
    In Swift, one cannot override extensions without
    @objc override
    , and using it to "fix" will lead to dynamic dispatch and the output "b" instead of "a". Overrides. The Kotlin type system is much more flexible when it comes to property and method overrides. It will take us some time to find workarounds for all reasonable corner cases 🙃 Interfaces. Our next big milestone is to support the export of Kotlin interfaces as Swift protocols. Implementing a full solution (e.g., allowing a random Swift struct to implement a random Kotlin interface and be passed to a Kotlin function) is highly challenging, but we will take a step-by-step approach to tackle it.
    🦠 40
    ❤️ 5
    a
    • 2
    • 1
  • a

    Angel Solis

    11/16/2024, 6:09 PM
    Hi 👋 Is there a way to make the output from swift export into an SPM package? We have a separate ios project that we would like it to use the kmp library as SPM
    g
    a
    w
    • 4
    • 8
  • u

    אליהו הדס

    11/18/2024, 2:16 PM
    Hello, Jetbrains is actually working on the kotlin Swift bridge, will this mean that we will be able to do Swift ui in kotlin? Or will it only be in one direction? https://blog.jetbrains.com/kotlin/2024/10/kotlin-multiplatform-development-roadmap-for-2025/#kotlin-to-swift-export
    👀 3
    a
    j
    c
    • 4
    • 4
  • j

    Jon Bailey

    12/05/2024, 3:03 PM
    I know this channel is for Swift Export, and it’s been said swift import is out of scope, but just saw a blog post from Skip.tools which does Swift -> Kotlin transpiling that they’ve added native Swift compilation for Android that can be consumed by Kotlin code. Would this help using Swift in a KMP project? https://skip.tools/blog/skip-native-tech-preview/
    p
    a
    +2
    • 5
    • 10
  • s

    sergey.bogolepov

    12/20/2024, 2:01 PM
    I'm pleased to share the latest developments in the Swift export project as we wrap up 2024! The Most Significant Changes in the Last Two Months • Implemented basic support for
    enum
    and
    sealed
    classes, which means all types of classes are covered except tricky
    value
    ones :D • Added support for simple method overrides. Not-so-basic covariant and fake overrides will come later after we implement support for interfaces. • Rolled out initial support for the
    @Throws
    annotation by translating it to an untyped
    throws
    . Current Focus Areas • Interfaces. Even though we excluded cross-language inheritance from the initial scope, interfaces remain very challenging to implement. • Functional types (aka closures/lambdas). Recently, we merged support for the
    () -> Unit
    type and are now expanding support for the rest of the possible signatures. We also need to ensure that throwing works properly, along with overrides. Oh man. Glimpse into the future For now, we are continuing to use a type system that is more or less the same as in Objective-C export (
    KotlinBase
    as the root of the class hierarchy). However, we see limitations of this approach and a potentially better option that promises to be much more flexible: KotlinBridgeable protocol. We will not switch to it before the first public release, but it is clearly something we want to explore as soon as possible. Thank you for following our progress—see you in the new year! 👋
    ♥️ 57
    👀 2
    a
    j
    a
    • 4
    • 10
  • d

    David

    01/21/2025, 6:41 AM
    Hi! Will the swift interop releases this year improve the naming of kotlin top level functions? so that you don't need to use something like this: Filename_iosKt.myFunctionCall() ?
    s
    • 2
    • 3
  • c

    colintheshots

    01/26/2025, 9:21 PM
    I was instrumenting a Compose Multiplatform app with Swift Export. I ran into this error I think because the Compose Controller function is implemented through UIKit through Objective-C. Is there a recommended solution to bring Swift Export code modules directly into a Compose Multiplatform app? Or is this simply not possible yet and I should focus on making separate Swift Export modules that don't expose any Compose code?
    Copy code
    > A failure occurred while executing org.jetbrains.kotlin.gradle.plugin.mpp.apple.swiftexport.internal.SwiftExportAction
    
       > Can't translate return type in fun MainViewController(): platform.UIKit.UIViewController: Symbol not found for platform/UIKit/UIViewController
    Copy code
    // from androidx.compose.ui.window
    import platform.UIKit.UIViewController
    
    fun ComposeUIViewController(content: @Composable () -> Unit): UIViewController =
        ComposeUIViewController(configure = {}, content = content)
    s
    • 2
    • 1
  • s

    Simon Frost

    02/03/2025, 1:24 PM
    are there any changes to swift export in Kotlin 2.1.10? didn’t see any in the change log
    s
    • 2
    • 2
  • a

    Alex Murphy

    02/04/2025, 5:05 PM
    Has anyone seen anything about value type (swift
    struct
    ) export on the roadmap? From what i've seen data class exports from Kotlin will still use reference types (swift
    class
    )
    ➕ 1
    s
    j
    • 3
    • 3
  • s

    sergio

    02/13/2025, 8:05 AM
    Hi guys! I have a question, is there any solution in development for integrate pure swift libraries into kmp with full shared ui and logic??
    f
    h
    b
    • 4
    • 41
  • m

    Mohamed Mabrouki

    02/13/2025, 10:11 AM
    hello, is there a way to import swift class that has observable propreties and be able to observe their changes in the kotlin ios code ? example swift code in thread.
    t
    • 2
    • 3
  • n

    Nadeen Ashraf

    02/20/2025, 11:04 AM
    Hello All! Does anyone know if it's possible to have a submodule in my kmp project containing a swift file, and if I can access that swift file from my main app's App Delegate ?
    x
    • 2
    • 1
  • g

    Grigory Panko

    03/20/2025, 11:00 AM
    Hi! Is there any way to track the causes of
    SirUnsupportedType
    appearing which later cause
    java.lang.IllegalStateException: Attempt to bridge unbridgeable type: SirUnsupportedType.
    ? I'm experimenting with Swift export in our project, and trying to export almost any module (trying to at least export dependencies before exporting our own modules) produces this exception. I've succeeded only with exporting single
    kotlin-stdlib
    , while having this exception with, for example,
    kotlinx-datetime
    ,
    ktor-http
    ,
    ktor-client-core
    or
    coroutines-core
    . Maybe there is some list of supported/unsupported types, or I'm just setting up something wrong?
    s
    • 2
    • 6
  • d

    Dmitriy Tarasevich

    04/19/2025, 5:43 PM
    I was eager to check out the swift export updates on the play.kotlinlang.org site but it seems on 2.20.0 it always returns Unexpected end of JSON input I know it's not done, just a heads up
    s
    s
    • 3
    • 2
  • m

    mattinger

    05/21/2025, 1:05 PM
    Hi everyone. I'm investigating using the new (experimental) swift export feature. One thing i've noticed right off the bat is that it's not handling default parameters in constructors.
    Copy code
    data class SomeClass(val value: Int = 0)
    I can't instantiate this in swift code without supplying the
    value
    parameter. I'm unable to use SKIE because we're modeling log data which has a large number of optional constructor parameters, which SKIE isn't good at handling (as it tries to create all the different permutations available) Is there something i'm missing, or is this just not something available yet?
    g
    • 2
    • 5
  • k

    kyungkoo

    06/12/2025, 1:08 AM
    Hi! Swift Export! Have you seen WWDC25 video? This video is about the interoperability between Java and Swift. Could this feature of Swift have a positive impact on kotlin-export?

    https://youtu.be/QSHO-GUGidA?si=o5exjsPksDYip33J▾

    j
    k
    f
    • 4
    • 5
  • m

    Marco Righini

    06/19/2025, 2:08 PM
    Hi! Is there any plan to expose swift export as a standalone gradle command that doesn't need to run in xcode? (e.g. for remote spm export)
    👍 3
    a
    • 2
    • 2
  • g

    Guilherme Delgado

    06/25/2025, 10:34 PM
    https://www.swift.org/android-workgroup/ 🚀
    👀 4
  • u

    ursus

    07/06/2025, 1:19 AM
    Will swift export alleviate the need for SKIE when exposing
    Flow<T>
    ?
    plus1 1
    a
    g
    • 3
    • 9
  • u

    ursus

    07/06/2025, 1:24 AM
    Will swift export make ios builds faster, slower or the same?
    a
    • 2
    • 1
  • h

    Hien Nguyen

    07/16/2025, 9:51 AM
    I have a multi-module mobile project. Android and iOS will keep their native platform UI without using KMP, but they will share business logic with each other. In the KMP business layer, we're using an umbrella framework to combine all KMP feature modules together. This was very hard to manage because each KMP feature module is managed by a different team. I have a question: I have a KMP module called Manager. In this Manager module, there is a class called FeatureManager that contains a list of FeatureInterfaces. The FeatureInterface will be used by other KMP modules like moduleA and moduleB to create classes that implement these FeatureInterfaces. The register method of FeatureManager will be called in the iOS app. Now I have upgraded to Kotlin 2.1.0. I want to stop using the umbrella module. Instead, each KMP module will create its own framework, and the iOS app will consume these frameworks. Is this possible for my above problem relating to Manager and moduleA, moduleB?
    g
    h
    • 3
    • 8
  • s

    Samuele Perricone

    07/16/2025, 3:16 PM
    are there any udpates to swift export in Kotlin 2.2.0 or newer betas? (like Kotlin 2.2.20-Beta1)? didn’t see any in the change log, but the YouTrack ticket mention that swift export is planned for 2.2.20-Beta2, thanks to the Jetbrain team that is working on it! 🙇
    c
    • 2
    • 1
  • s

    soderbjorn

    07/31/2025, 9:43 PM
    I'm trying out 2.2.20-beta2 with the Swift export! 😍 However, I have a problem with
    suspend
    functions. In the past they were exported to ObjectiveC and very easy to call from Swift, e.g.:
    viewModel.run() { error in
    if let error = error {
    // ...
    }
    }
    Now, looking at the generated Swift source code, my
    suspend
    functions are completely excluded from export! 😱 Other functions in the same class are exported, even with similar (empty) method signature, as long as they are not
    suspend
    functions. I must be missing something here. What might be going on? 🤔 Edit: Hmm, I guess this is probably just a consequence of coroutines not being supported yet.
    😢 4
    g
    • 2
    • 2