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

Damiano Giusti

11/06/2023, 2:39 PM
Hello! I would like to take advantage of the
callAsFunction
operator in Swift like the
operator fun invoke
function in Kotlin. I tested its feasibility and by using
@ObjCName("callAsFunction")
I’m able to achieve that behavior. Is there a way to declare an annotation that applies the ObjCName renaming to the annotated function? I thought that this would have worked but it didn’t…
Copy code
@OptIn(ExperimentalObjCName::class)
@ObjCName("callAsFunction")
annotation class SwiftCallAsFunction
my goal is to avoid to repeat the
"callAsFunction"
string everywhere is needed. I thought about using a constant but I would like to understand if there are other ways thanks!
🍿 1
1
e

Edoardo Luppi

11/06/2023, 2:44 PM
No it won't work. You need a compiler plugin. But keep it simple.
j

juliocbcotta

11/06/2023, 6:13 PM
Maybe it's something that the folks at #touchlab-tools can help?
d

Damiano Giusti

11/07/2023, 9:23 AM
I’ll try to post it also in that channel, thanks
2 Views