https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
m

Marc Knaup

06/06/2019, 2:51 PM
It would be cool if a multiplatform projects can somehow reflect a platform's naming conventions. E.g. having a property named
websiteUrl
in Kotlin and
websiteURL
in ObjC/Swift 🙂
d

Dominaezzz

06/06/2019, 3:31 PM
The can!
With attributes like
@JvmName
.
m

Marc Knaup

06/06/2019, 3:32 PM
That would change the name for Java, not for Kotlin.
And about JS? Or different native targets? 🙂
d

Dominaezzz

06/06/2019, 3:33 PM
They have theirs but I don't remember what they're called.
a

Artyom Degtyarev [JB]

06/06/2019, 3:57 PM
There definitely are CName and JsName, just dig deeper to the Reference(https://kotlinlang.org/api/latest/jvm/stdlib/index.html). Not sure it has the same for ObjC, because of the prefix thing. But I suppose you are talking about importing ObjC things and making them prettier by default, don’t you?
m

Marc Knaup

06/06/2019, 4:20 PM
@CName
seems to be for a different purpose though:
Makes top level function available from C/C++ code with the given name.
Even though it's documented I cannot actually use it in my code. It doesn't exist 😮
a

Artyom Degtyarev [JB]

06/06/2019, 4:36 PM
Did you import something like a
kotlin.native.CName
? In example here https://github.com/JetBrains/kotlin-native/tree/master/backend.native/tests/produce_dynamic/simple it looks like this should help. And yes, I might be misleading with it’s purpose, but I’m not sure what kind of name-changing you want to achieve.
m

Marc Knaup

06/06/2019, 4:38 PM
It's probably not available because I'm in am multiplatform project with iOS target and not in a purely native Kotlin project. Also, I need to declare the name in common code, not in platform code.
r

russhwolf

06/06/2019, 4:50 PM
You can try declaring
@OptionalExpectation annotation class CName
in your common code and
actual typealias CName = kotlin.native.CName
in your native. I haven't tried
CName
on iOS though so I don't know if there's something different for ObjC.
m

Marc Knaup

06/06/2019, 5:22 PM
True, thanks.
CName
is for
C
exports 🙂 iOS code is ObjC which is very different and Swift will be even more different.
r

russhwolf

06/06/2019, 5:41 PM
Yeah. I have no idea if it works or not but since https://youtrack.jetbrains.com/issue/KT-28801 is closed and the only thing that exists is
@CName
and not a separate
@ObjCName
, I figure maybe it's worth a try. Definitely nothing Swift-specific exists right now though because Kotlin only interops with Obj-C
m

Marc Knaup

06/06/2019, 5:42 PM
As I said, I have no
CName
in my project. Neither in common code, nor in platform code 😕
s

svyatoslav.scherbina

06/07/2019, 8:03 AM
CName
doesn’t affect produced Objective-C/Swift API.
ObjCName/SwiftName
is not available yet.
👌 1
r

russhwolf

06/07/2019, 12:05 PM
Is there a ticket to track when that will be available?
3 Views