❗️ Swift export is in very early stages of development. Things change very quickly, and documentation might not catch up at times.
Swift export is a tool that generates Swift bindings for public Kotlin declarations, making it possible to share business logic between Kotlin and Swift applications.
❗️ (Yep, again) Swift export is far even from Alpha state at the moment. We are working hard to make it feature-complete and stable.
swift-export-sample provides an example of using Swift export in a typical KMP project.
You can play with Swift export at the Kotlin playground to get familiar with the Swift API it generates.
A few notes:
stub()
in functions instead of compiler bridges to make the generated API a bit cleaner.You can play with Swift export without KGP. Note that it might be a bit tricky at the moment:
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev")
// Make sure to use the latest versions of artifacts. val kotlinVersion = "2.0.20-dev-+" implementation("org.jetbrains.kotlin:kotlin-native-utils:$kotlinVersion") implementation("org.jetbrains.kotlin:kotlin-compiler-embeddable:$kotlinVersion") implementation("org.jetbrains.kotlin:swift-export-embeddable:$kotlinVersion")
val inputModule = InputModule.Binary("ModuleName", Path("path-to-input-klib")) val config = SwiftExportConfig( outputPath = Path("path-to-output-artifacts"), distribution = Distribution( konanHome = "$HOME/.konan/some-kotlin-native-distribution" ), ) val result = runSwiftExport(inputModule, config) // explore the result!
We use the #swift-export
Slack channel as the place to share our progress, and we encourage you to join us there!