Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not able to use Kotlin Extension Function written in common in iOS as Swift Extension

I have a Kotlin Multiplatform project setup with Android & cocoapods for iOS.

I have a file Extensions.kt in commonMain/src with the following function:

fun String.isValidEmail(): Boolean {
    return validate(ValidatorRegex.EMAIL)
}

I am able to access this function in Android as a String extension:

"[email protected]".isValidEmail()

But in iOS using Swift, I need to call it as a static method of another class:

ExtensionsKt.isValidEmail("[email protected]")

It should convert that commonMain/src method to a Swift extension of String instead of a class with a static method.

Am I missing any configuration?

like image 350
Pinakin Kansara Avatar asked Feb 04 '20 04:02

Pinakin Kansara


1 Answers

You're doing everything right here. Unfortunately, this option is not available for now. Extensions conversion may be performed correctly for some classes, but Swift's String is not the one. This is a known inconvenience, and K/N team is working hard to make it better.

like image 118
Artyom Degtyarev Avatar answered Sep 29 '22 09:09

Artyom Degtyarev