Interop annotation - @HiddenFromObjC
@HiddenFromObjC hides a Kotlin declaration from Objective-C/Swift. Experimental.
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.
Since the annotation is experimental, it is necessary to opt-in.
sourceSets {
all {
languageSettings.optIn("kotlin.experimental.ExperimentalObjCRefinement")
}
}
With thanks to Rick Clephas for the annotation contribution and example code.