SKIE (Swift Kotlin Interface Enhancer)

repository·main·Indexed 23 days ago

https://github.com/touchlab/skie

A tool for Kotlin Multiplatform (KMP) development that automatically enhances the Swift API published from Kotlin to provide a more idiomatic developer experience for iOS engineers. It includes features such as wildcard export prevention to resolve name collisions between Kotlin classes and Objective-C/Swift modules like Foundation.

Tokens
634
Snippets
1
Records
4
Agent score
29%

What's inside SKIE

  1. What is SKIE?

    main
    SKIE (Swift Kotlin Interface Enhancer) is a tool designed for Kotlin Multiplatform (KMP) development. It automatically enhances the Swift API that is published from Kotlin code, making the interface more idiomatic and easier to use for iOS developers.
  2. Understand Wildcard Export Prevention

    main

    By default, Kotlin frameworks (and other Objective-C frameworks) re-export all their dependencies via export * in their modulemap file. This means importing your Kotlin framework in Swift also makes transitive symbols (like Foundation) available without an explicit import.

    The Problem: When SKIE adds a Swift overlay, it can create name collisions. For example, if your Kotlin code has a class named Locale, it becomes Locale in Swift. Since Foundation also has a Locale type, importing both Kotlin and Foundation in a Swift file creates an ambiguity that prevents type lookup and causes compilation errors.

    SKIE solves this by removing the export * and module * { export * } lines from the Kotlin framework's modulemap, preventing transitive re-exports.

  3. Disable Wildcard Export Prevention

    main

    If you need to maintain the default behavior where dependencies are re-exported (for example, to avoid adding explicit import Foundation statements to all your Swift files), you can disable SKIE's wildcard export prevention in your build.gradle.kts file.

    Warning: Disabling this feature may cause Swift compilation to fail if your Kotlin code contains class names that conflict with symbols in your dependencies (e.g., a Kotlin class named Locale conflicting with Foundation.Locale).

    skie.isWildcardExportPrevented.set(false)
  4. Troubleshoot Ambiguous Type Errors in Swift

    main

    If you encounter errors like Ambiguous type name 'Locale' in module 'Kotlin' or similar ambiguity errors during Swift compilation after applying SKIE, it is likely due to a name collision between your Kotlin code and an imported module (like Foundation).

    Solutions:

    1. Enable Wildcard Export Prevention (Recommended): Ensure skie.isWildcardExportPrevented is set to true (the default). Note that this will require you to add explicit import statements (e.g., import Foundation) to any Swift files that use symbols from those dependencies.
    2. Rename Kotlin Classes: Rename the conflicting classes in your Kotlin code so they do not match common names in Objective-C/Swift modules.
    3. Disable Module Interface Verification: As a last resort, you can disable module interface verification (see SKIE Issue #400).