Kotlin-native: Changing name for Objc methods

Created on 29 Oct 2019  路  4Comments  路  Source: JetBrains/kotlin-native

Hi!
In kotlin multiplatform I have the following code:
fun withUserId(userId: String) = applySelf { this.userId = userId }

And it's converted in Objective-C like that:
- (MyClass *)withUserIdUserId:(NSString *)userId __attribute__((swift_name("withUserId(userId:)")));

And when I call the method, my method name is doubled:

[user withUserIdUserId:@"testId"]

How can I omit these doubling? As I know, kotlin have @JsName for Javascript method names, does it have similar for Objective-C methods?

Thanks,
Nazariy

Most helpful comment

I would love to be able to override the obj-c naming with an annotation.

All 4 comments

Hello!
Can you please share a few more complex example of the Kotlin code you're using?

I would love to be able to override the obj-c naming with an annotation.

Hello!

Similar need on my side, as I often have the swift names prefixed with the file name.
For instance:
fun print() in Common.kt
becomes swift_name("CommonKt_print")

And I would also love to have access to an annotation to instrument the name or even the prefix in files that happen to end up with such weird things...

Thank you!

Hello!

The problem is still relevant today.

Was this page helpful?
0 / 5 - 0 ratings