Skip to content

Latest commit

 

History

History
41 lines (31 loc) · 1.06 KB

HiddenFromObjC.md

File metadata and controls

41 lines (31 loc) · 1.06 KB

Interop annotation - @HiddenFromObjC

@HiddenFromObjC hides a Kotlin declaration from Objective-C/Swift. Experimental.

Explanations

In Kotlin:

@HiddenFromObjC
fun myKotlinOnlyFunction(){
    println("Only Kotlin!")
}

In Swift:

func hiddenFromObjCExample(){
    //Uncommenting gives compilation error
    //myKotlinOnlyFunction()
}

Using the @HiddenFromObjC annotation, we can prevent the export of this function to Objective-C/Swift. This is different from using the internal keyword, because the construct can still be used from other Kotlin compilation units, just not from Objective-C/Swift.

Setup

Since the annotation is experimental, it is necessary to opt-in.

sourceSets {
    all {
        languageSettings.optIn("kotlin.experimental.ExperimentalObjCRefinement")
    }
}

Credits

With thanks to Rick Clephas for the annotation contribution and example code.


Table of contents