@ObjCNameとSwift向けAPI
Swiftの呼び出し側で自然に読める形にエクスポートを整えます
「@ObjCNameとSwift向けAPI」はCoddyKit上の無料Kotlin Multiplatform Academyレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはKotlin Multiplatform Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Kotlin Multiplatform Academyコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
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 UserRepositoryCleaner 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. 🎉
よくある質問
「@ObjCNameとSwift向けAPI」レッスンは無料ですか?
はい。「@ObjCNameとSwift向けAPI」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Kotlin Multiplatform Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Kotlin Multiplatform Academyコースには全4レッスンが含まれています。
「@ObjCNameとSwift向けAPI」で何を学びますか?
Swiftの呼び出し側で自然に読める形にエクスポートを整えます ブラウザで直接実行するハンズオンコードでKotlin Multiplatform Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Kotlin Multiplatform Academyを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのKotlin Multiplatform Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。
「@ObjCNameとSwift向けAPI」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このKotlin Multiplatform Academyレッスンでコードを書いて実行できますか?
はい。すべてのKotlin Multiplatform Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- KotlinからObjective-Cへのマッピング方法
- Swift asyncとしてのSuspend Functions
- SwiftからFlowをcollectする
- @ObjCNameとSwift向けAPI