@ObjCName gives better Objective-C/Swift names to Kotlin constructs like classes, functions and so on, without actually renaming the Kotlin constructs. Experimental.
In Kotlin:
@ObjCName(swiftName = "MySwiftArray")
class MyKotlinArray {
@ObjCName("index")
fun indexOf(@ObjCName("of") element: String): Int = 1
}
In Swift:
let array = MySwiftArray()
let index = array.index(of: "element")
Here we are renaming a class, function, and its parameter using the @ObjCName
annotation so that we can use the alternative names from Objective-C/Swift. This is especially useful to change the Swift names of constructs to more idiomatic names without actually renaming them in Kotlin.
Since the annotation is experimental, it is necessary to opt-in.
sourceSets {
all {
languageSettings.optIn("kotlin.experimental.ExperimentalObjCName")
}
}
With thanks to Rick Clephas for the annotation contribution and example code.