0Pricing
Kotlin Multiplatform Academy · Lesson

@ObjCName & Swift-Friendly APIs

Shape exports so Swift call sites read naturally.

@ObjCName & Swift-Friendly APIs is a free Kotlin Multiplatform Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Kotlin Multiplatform Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Make Swift Devs Happy

Your shared API should read naturally in Swift. A few annotations and habits make the bridge feel native, not bolted on.

Rename with @ObjCName

The @ObjCName annotation lets you give a type or function a different name on the Swift side without renaming the Kotlin one.

@ObjCName("UserService")
class UserRepository

Cleaner Method Names

Use @ObjCName on functions too, so a verbose Kotlin name becomes a short, idiomatic Swift call site that reads well.

@ObjCName("load")
fun loadUserData()

Avoid Name Clashes

Kotlin allows overloads that Obj-C cannot express. Renaming with @ObjCName prevents the mangled names Swift would otherwise see.

Hide with @HiddenFromObjC

Mark internal helpers with @HiddenFromObjC so they never appear in the framework, keeping the Swift surface small and clean.

@HiddenFromObjC
fun internalCache()

Default Arguments Vanish

Kotlin default arguments do not cross the bridge, so Swift sees one full signature. Provide overloads if Swift needs choices.

Favor Simple Types

Expose plain data classes and primitives at the boundary. Deep generics and sealed hierarchies get awkward for Swift callers.

Watch Property Names

A Kotlin isActive boolean reads great in Swift, but odd getter names can look clumsy, so name properties with Swift in mind.

Document for iOS

Add KDoc on exported members. Some of it surfaces in Xcode, helping iOS devs use your shared API without guessing.

Test the Call Sites

Open the generated header or a Swift file and actually read how your API looks. If it feels clunky, refine the annotations.

A Polished Bridge

Thoughtful naming and hiding turn shared Kotlin into an API Swift devs enjoy, making cross-team work smooth and friendly.

Quick Check

Let us check what @ObjCName is for.

Recap

Shape exports with @ObjCName and @HiddenFromObjC, favor simple types, and read the real Swift call sites. A friendly bridge wins. 🎉

Frequently asked questions

Is the “@ObjCName & Swift-Friendly APIs” lesson free?

Yes — the full text of “@ObjCName & Swift-Friendly APIs” is free to read here on the web, and the Kotlin Multiplatform Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Kotlin Multiplatform Academy course, upgrade to CoddyKit PRO.

What will I learn in “@ObjCName & Swift-Friendly APIs”?

Shape exports so Swift call sites read naturally. You practise Kotlin Multiplatform Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Kotlin Multiplatform Academy?

No prior experience is required. Kotlin Multiplatform Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “@ObjCName & Swift-Friendly APIs” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Kotlin Multiplatform Academy lesson?

Yes. Every Kotlin Multiplatform Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. How Kotlin Maps to Objective-C
  2. Suspend Functions as Swift async
  3. Collect Flows from Swift
  4. @ObjCName & Swift-Friendly APIs
← Back to Kotlin Multiplatform Academy