Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk4 min

How a Kotlin Class Name Can Break a Kotlin Multiplatform Build with SwiftUI

Kotlin/Native can rename same-named classes from different packages when they enter one Objective-C framework. Here’s how to verify a collision and choose a fix.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A class-name collision is one possible cause of a Kotlin Multiplatform framework integration failure involving SwiftUI: Kotlin package names do not become namespaces in the Objective-C-facing framework API. If two exported Kotlin classes share a name, Kotlin/Native may rename them, and its naming algorithm can change between Kotlin releases. Confirm what the framework actually exports before changing code; the title alone does not establish the cause of a particular build error.

Why Kotlin package names may not protect class names

Kotlin source code can contain classes with the same name in different packages. For example, separate packages might each define a class named Settings. But when Kotlin/Native exposes declarations through an Objective-C framework, the Kotlin package boundaries do not function as namespaces for those classes in the framework API. If both classes are exported into the same framework, their names can collide on that surface.

As an Amazon Associate I earn from qualifying purchases.

Kotlin/Native may resolve the conflict by renaming declarations in the generated Objective-C-facing API. The Kotlin documentation cautions that “This algorithm is not stable yet and can change between Kotlin releases.” That means a name observed in one generated framework should not be treated as a stable, intentional Swift API across Kotlin upgrades.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How to check whether this is your build problem

A SwiftUI or Xcode build failure is not, by itself, proof of a Kotlin name collision. Check the framework’s generated Objective-C header and the framework’s exported surface. Kotlin’s interoperability documentation describes how declarations are exposed to Objective-C and Swift; Apple’s documentation provides general context on generated headers and references between Swift declarations and Objective-C headers.

  1. Find the generated framework header. Inspect the header produced for the framework that the Swift target imports. Look for the affected class name and any altered or disambiguated names.
  2. Trace declarations back to Kotlin. Check whether classes with the same Kotlin class name come from different packages and whether both are visible to the Swift-facing framework.
  3. Check framework export settings. Exported dependency APIs can be included in a framework, so inspect which dependencies are exported—not just the declarations in the app’s main Kotlin source set. Kotlin documents framework creation and dependency export in Build final native binaries.
  4. Compare the header with the failing reference. Confirm whether Swift code or another header consumer refers to a name that the generated framework actually exposes. If the names line up, investigate the error on its own terms; other SwiftUI, Xcode, or framework integration problems need separate diagnosis.

For the interoperability details, see Kotlin’s Interoperability with Swift/Objective-C. Apple’s Importing Swift into Objective-C is relevant to generated-header context, but does not identify SwiftUI as the cause of Kotlin class-name collisions.

What to change when two exported classes collide

Rename the conflicting Kotlin classes

Kotlin’s documented workaround is direct: “To work around this issue, rename the conflicting Kotlin classes in the framework.” Give the Kotlin declarations distinct names, then regenerate the framework and inspect the header again. This addresses the collision at its source and avoids relying on an automatically chosen exported name that may change between Kotlin releases.

Renaming changes the Swift-facing API names. Search Swift call sites and any other consumers of the generated header, then update references to match the regenerated framework. Check the header after the change rather than assuming a source-level rename produced the expected exported spelling.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Hide a declaration only if Swift does not need it

@HiddenFromObjC can keep a declaration out of the Objective-C and Swift surface while leaving it visible to other Kotlin modules. Kotlin’s internal visibility limits access to the compilation module. Either can reduce what enters the exposed API, but neither is appropriate when Swift needs to use that declaration. Kotlin documents these controls in its Swift/Objective-C interoperability guidance.

Do not assume a framework-name change fixes the collision

Kotlin class names imported into Objective-C receive a prefix derived from the framework name. That naming fact does not establish that changing the framework name resolves two same-named Kotlin declarations inside the same framework. Kotlin’s stated collision workaround is to rename the conflicting Kotlin classes, not to rename the framework.

What framework exports change in the investigation

A framework can contain Kotlin declarations and APIs from dependencies selected for export. Consequently, two classes that look unrelated in the main project may both reach the same framework through exported dependencies. Check the actual export configuration and the resulting header before deciding which declaration to rename or exclude.

Kotlin also supports transitive dependency export, which can bring additional APIs into the framework. The Kotlin build documentation discourages transitive export in most cases because of compilation-time and binary-size effects. For a name-collision investigation, its practical significance is that a broader exported surface can introduce declarations that need to be considered.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Is Swift export a drop-in alternative?

Kotlin’s Swift export preserves package structure and supports separate Swift modules, which speaks directly to the namespace problem. However, Kotlin labels Swift export Alpha; the documentation lists limitations and says it currently requires direct integration. Treat it as an evolving option to evaluate against your project’s integration and feature requirements, not as a universal or immediate repair for an existing framework build. See Interoperability with Swift using Swift export for the current documented status and constraints.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.