0Pricing
Kotlin Multiplatform Academy · Aula

@ObjCName e APIs amigáveis ao Swift

Estruture as exportações para que as chamadas em Swift sejam naturais

@ObjCName e APIs amigáveis ao Swift é uma aula grátis de Kotlin Multiplatform Academy no CoddyKit. Esta é a aula 4 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Kotlin Multiplatform Academy, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Kotlin Multiplatform Academy inclui 4 aulas no total.

Partes desta aula ainda não foram traduzidas e aparecem em inglês.

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. 🎉

Perguntas Frequentes

A aula “@ObjCName e APIs amigáveis ao Swift” é grátis?

Sim — o texto completo de “@ObjCName e APIs amigáveis ao Swift” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Kotlin Multiplatform Academy, atualize para CoddyKit PRO. O curso de Kotlin Multiplatform Academy inclui 4 aulas no total.

O que vou aprender em “@ObjCName e APIs amigáveis ao Swift”?

Estruture as exportações para que as chamadas em Swift sejam naturais Você pratica Kotlin Multiplatform Academy com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.

Preciso ter experiência prévia para começar Kotlin Multiplatform Academy?

Nenhuma experiência prévia é necessária. Kotlin Multiplatform Academy no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 4 de 4.

Quanto tempo leva a aula “@ObjCName e APIs amigáveis ao Swift”?

A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.

Posso escrever e executar código nesta aula de Kotlin Multiplatform Academy?

Sim. Cada aula de Kotlin Multiplatform Academy inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.

Todas as aulas deste curso

  1. Como Kotlin é mapeado para Objective-C
  2. Funções suspend como async do Swift
  3. Colete Flows a partir do Swift
  4. @ObjCName e APIs amigáveis ao Swift
← Voltar para Kotlin Multiplatform Academy