SKIE (Swift Kotlin Interface Enhancer)
repository·main·Indexed 23 days ago
https://github.com/touchlab/skieA 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.
What's inside SKIE
- 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.
Understand Wildcard Export Prevention
mainBy default, Kotlin frameworks (and other Objective-C frameworks) re-export all their dependencies via
export *in theirmodulemapfile. This means importing your Kotlin framework in Swift also makes transitive symbols (likeFoundation) 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 becomesLocalein Swift. SinceFoundationalso has aLocaletype, importing bothKotlinandFoundationin a Swift file creates an ambiguity that prevents type lookup and causes compilation errors.SKIE solves this by removing the
export *andmodule * { export * }lines from the Kotlin framework'smodulemap, preventing transitive re-exports.Disable Wildcard Export Prevention
mainIf you need to maintain the default behavior where dependencies are re-exported (for example, to avoid adding explicit
import Foundationstatements to all your Swift files), you can disable SKIE's wildcard export prevention in yourbuild.gradle.ktsfile.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
Localeconflicting withFoundation.Locale).skie.isWildcardExportPrevented.set(false)Troubleshoot Ambiguous Type Errors in Swift
mainIf 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 (likeFoundation).Solutions:
- Enable Wildcard Export Prevention (Recommended): Ensure
skie.isWildcardExportPreventedis set totrue(the default). Note that this will require you to add explicitimportstatements (e.g.,import Foundation) to any Swift files that use symbols from those dependencies. - Rename Kotlin Classes: Rename the conflicting classes in your Kotlin code so they do not match common names in Objective-C/Swift modules.
- Disable Module Interface Verification: As a last resort, you can disable module interface verification (see SKIE Issue #400).
- Enable Wildcard Export Prevention (Recommended): Ensure