How Kotlin Multiplatform exposes shared code as Swift modules, maps coroutines to Swift concurrency, and changes the way we should design shared APIs.Kotlin Multiplatform has never had a fundamental problem calling shared Kotlin code from Swift. It has had a problem making that interaction feel natural.Kotlin/Native traditionally exposes Kotlin declarations as Objective-C compatible frameworks.These can be used from Swift, however, due to how Objective-C compatibility is handled, the resulting API may not be very natural.n particular, the package names, automatically generated class names, nullability, generics, and asynchronous functions are applied in a way that may not be very familiar to a Swift developer.Swift export addresses that boundary.Rather than mapping to an Objective-C API, Kotlin declarations are mapped to Swift modules. As a result, packages, overloaded functions, type aliases, and concurrency features are more naturally expressed in Swift.This is a great improvement. However, this does not mean that Kotlin becomes Swift, nor that we can avoid designing an API with specific consumers in mind.We still have to make some decisions on what code should be in the shared module and what should be in the iOS app.The problem with the traditional interoperability boundaryA typical Kotlin Multiplatform project shares business logic through a common module:Domain models and business rules.Repository contracts and implementations.Networking and persistence logic.Use cases and application-level services.The API is consumed by the Android application through Kotlin. The iOS application consumes the generated Kotlin framework through Swift interoperability.The conventional way uses Kotlin/Native to generate Objective-C compatible declarations that are imported by Swift.This works, but the resulting API doesn’t necessarily reflect how a Swift developer would design the same interface.As an example, there is the case when Kotlin package names and declarations may create generated names which will be inconvenient to navigate. There are some Kotlin types which require wrappers for preserving their nullability.These are not necessarily problems with the Kotlin implementation itself. They’re consequences of translating one language’s type system and runtime into another interoperability model.Swift export changes that translation layer.What Swift export actually generatesSwift export generates Swift-facing modules from Kotlin declarations. Kotlin modules can appear as separate Swift modules, while package information is preserved to reduce naming collisions.This means Swift code can work with module-specific imports instead of navigating the naming conventions associated with the Objective-C bridge.Consider a Kotlin module containing:package com.example.sharedclass UserRepository { fun getUserCount(): Int = 42}For traditional interoperability, the generated API will be affected by the Objective-C naming convention.For Swift export, the Kotlin classes and the members are converted into Swift versions more directly.Some generated artifacts are the Swift module file, static library, header, and the module map. It would be good to understand that there are still some generated native artifacts; Swift export does not negate compilation and the native integration.There are several useful improvements:Module and package preservation. Kotlin modules can be exported independently, and packages can be represented in the Swift module structure. The package prefix can also be flattened when that makes the API easier to consume.Improved nullability. Nullable primitive values can retain their nullability information without the same kind of wrapper types required by traditional Objective-C interoperability.Overloaded functions. Kotlin overloads can be exposed without forcing developers to work around ambiguous generated names.Type aliases. Kotlin type aliases are kept when generating the Swift API.This makes the above improvements especially important in big KMP projects that have several modules exposing their own independently developed APIs.A shared networking module, a domain module, and an analytics module will no longer all be part of the same interoperability layer.Kotlin types don’t all become Swift types in the same waySwift export provides a more direct Swift representation, but the mapping still follows Kotlin’s type system.For example:A few mappings deserve attention.Kotlin Int becomes Swift Int32, not Swift's platform-sized Int. Kotlin Char becomes Unicode.UTF16.CodeUnit. A Kotlin object is represented as a Swift class with a static shared accessor.Classes also inherit from the generated KotlinRuntime.KotlinBase type.These details matter when designing an API that will be consumed by developers who expect conventional Swift interfaces.Other distinctions that should be noted include the following:Functions in Kotlin that use extensions become regular Swift functions where the receiver becomes the first argument.vararg functions in Kotlin convert into variadic parameters in Swift.enums in Kotlin maps into native enum in Swift.Sealed classes and interfaces can be represented as Swift enums, supporting exhaustive switch statements.The last point is particularly useful for shared domain results.For example, a result type hierarchy in Kotlin may reveal a group of cases which can be handled exhaustively by Swift. With any modification to the hierarchy of Kotlin, Swift will be able to detect missing cases instead of accepting a fall back case.Kotlin 2.4.20 added the ability to work with such sealed hierarchies in order to make the boundary very practical for applications with shared domain-level result types.Concurrency is one of the most valuable improvementsFor many KMP applications, asynchronous API interoperability is more significant than the improved naming conventions.Consider a repository that exposes a suspending function and a Flow:class UserRepository { suspend fun getUser(id: String): User { // Fetch and return user } fun observeUser(id: String): Flow { // Observe user updates }}In a traditional integration, exposing these asynchronous constructs to Swift often required additional interoperability infrastructure.Swift export provides direct mappings.A Kotlin suspend function is exposed as a Swift async function:let user = try await repository.getUser(id: "42")A Kotlin Flow can be consumed through Swift's AsyncSequence:for try await user in repository .observeUser(id: "42") .asAsyncSequence() { print(user)}The module generated and package structure may affect the exact call site, but these examples show the intended API shape.This is a substantial improvement for teams already using Swift concurrency.It becomes possible to process asynchronous operations via the use of known programming languages structures in the iOS application, rather than requiring each shared API to be written around callbacks or some kind of interoperable reactive layer.However, there is one caveat: making Flow available as AsyncSequence doesn’t make all the lifecycle semantics of Kotlin Flow equivalent to those of Swift’s native asynchronous sequences.Cancellation, completion, error handling still need to be covered by integration tests. Just because something compiles successfully doesn’t mean you have an API with the desired lifecycle semantics.Setting up Swift export in a Kotlin Multiplatform projectThe configuration depends on the Kotlin version.For the stable Kotlin 2.4.x line, the documented configuration uses the swiftExport Gradle block.For example:kotlin { iosArm64() iosSimulatorArm64() swiftExport { moduleName = "Shared" flattenPackage = "com.example.shared" }}Here:moduleName defines the Swift module name.flattenPackage specifies the package prefix to remove from the generated Swift API.After configuring the Kotlin module, the Xcode integration needs to invoke the Swift export task.In the Xcode project’s Build Phases, locate the Run Script phase that uses:./gradlew :shared:embedAndSignAppleFrameworkForXcodeReplace the integration script with:./gradlew :shared:embedSwiftExportForXcodeBuilding the project generates the Swift modules and associated artifacts needed by the Xcode project.This documented integration path currently requires direct integration between the Kotlin Multiplatform module and the Xcode project.It isn’t simply a matter of changing the generated framework’s import statement. The Gradle and Xcode build integration must agree on the export mechanism.An important Kotlin version changeThe Gradle DSL is evolving alongside Swift export itself.Kotlin 2.5.0-RC introduces a revised DSL:kotlin { iosArm64() iosSimulatorArm64() export { swift { moduleName = "Shared" rootPackage = "com.example.shared" } }}The new architecture also makes changes in the way dependencies are exported in Swift. The declared api dependencies can now be auto-exported, and the specific overrides for the dependencies can be configured using xcodeIntegration.It is not merely a name change. The new architecture makes the process of configuring the modules easier as well as makes export settings easier to publish and consume across KMP libraries.But Kotlin 2.5.0-RC is a preview version and not the current stable version of Kotlin. The Swift export Beta in the preview version should not be confused with the Alpha implementation in the current stable 2.4.x series.In case you have a production project, please select the configuration according to your actual version of the Kotlin Gradle plugin instead of copying a DSL example from a newer release.Where Swift export still has limitationsAn enhanced representation in the API does not necessarily imply that all Kotlin declarations are exposed naturally.There are certain documented limitations.Generic types remain restricted.Generic types are usually not allowed; generic type parameters may be erased to their upper bounds.This is useful when designing public repository interfaces, result wrappers, and reusable domain abstractions.An API that depends heavily on generic return types may need a more explicit export-facing representation.Collection inheritance needs attention.The types that inherit from List, Set, or Maphave restrictions when it comes to exports. Some of them are ignored during export, while other collection types cannot be created in Swift.Designing exported contracts using regular collection types is better than designing your own custom collection inheritance hierarchy.Integration constraints remain.The documented Alpha workflow currently requires direct Xcode integration. Existing project structures that rely on different integration approaches need to be evaluated before adopting Swift export.API evolution still needs coordination.Kotlin declarations cease to be mere internal implementation details when the iOS app starts using them. Any changes made to their names, packages, types, or method signatures impact the Swift API contract.These limitations don’t make the feature irrelevant. This is where the team needs to be careful.Design the shared module for its consumersThe greatest architectural error would be treating the Swift export as a build configuration change.A shared module will have at least two consumers of its API: Kotlin-based applications and Swift-based applications.These consumers may not have similar requirements.An API that feels convenient in Kotlin may expose awkward abstractions in Swift. A deeply generic repository contract, for example, might be perfectly reasonable inside a Kotlin codebase but unsuitable for the current Swift export type mapping.I would start by considering the API for the Swift language as a concrete architectural boundary.Implementation should be hidden when possible. Instead, expose contracts within the domain space, clear result types, and async operations that match the target language well.Pay keen attention to:Whether exported types have useful Swift representations.Whether domain results can be handled exhaustively.Whether async operations have predictable cancellation and error behavior.Whether module and package names make sense to iOS developers.Whether the public API depends on generic declarations that Swift export cannot represent.We don’t have to duplicate our domain layerin Swift, nor have different business logic in Android and iOS.We just need to be responsible for the interface between the shared implementation and the native clients.Swift export is an API improvement, not an architecture replacementSwift export is a great addition to Kotlin Multiplatform, allowing much easier interaction between the Kotlin API developers and Swift API iOS developers.The direct module export, improved null safety, native enum support and structured concurrency all contribute to an easy to interact with API.The additions in Kotlin 2.4.20, particularly sealed hierarchy support and cross-language inheritance, extend its usefulness beyond straightforward function calls.Limitations still exist in relation to generics, collection inheritance, and project support. The maturity of Kotlin is dependent on the particular release of Kotlin used.My recommendation is to test the Swift export starting from the edge of a representative shared module. This test should include the suspend function, Flow, sealed result hierarchy, and domain models that are really needed by the iOS app. The generated API can then be tested from Xcode before migrating more modules.The goal is not merely to reduce the number of generated names when importing Kotlin code into Swift.It is to have a shared module that feels like a well-designed library to both platforms, while maintaining the architectural properties that made it worth sharing.SourcesInteroperability with Swift using Swift export — Kotlin Documentation, JetBrains.What’s new in Kotlin 2.4.20 — JetBrains. Covers sealed class support, exhaustive Swift switches, and cross-language inheritance.What’s new in Kotlin 2.5.0-RC — JetBrains. Covers Beta status and the revised Gradle DSL.Swift package export setup — JetBrains.Swift Export in Kotlin Multiplatform: What Changes at the Swift Boundary was originally published in ProAndroidDev on Medium, where people are continuing the conversation by highlighting and responding to this story.
Swift Export in Kotlin Multiplatform: What Changes at the Swift Boundary
Swift Export in Kotlin Multiplatform: What Changes at the Swift Boundary
Editor
Nov 22, 2026 · 11 min read

From other categories

Security
Most Wanted: The Phishing Kits and Techniques Getting Past Security Controls
just now·1 min

AI & Machine Learning
Quoting Jack Despain Zhou
34m ago·1 min

Hardware
Scientific Analysis of Nontraditional Garden Watering Method
44m ago·3 min

Operating Systems
Security updates for Thursday
2h ago·2 min

Databases
Cornelia Biacsics: Contributions for week 46
4h ago·2 min
![Episode 76 “Java in the Age of AI” [AtA]](/_next/image?url=https%3A%2F%2Fapi.wrkm.app%2Fstorage%2Fmedia%2Ffeeds%2F2026%2F11%2Fab2f03b6f2b125c45205d40006845b5d7b3825da.jpg&w=3840&q=75)
Programming Languages
Episode 76 “Java in the Age of AI” [AtA]
16h ago·1 min