Hello everyone!
I wanted to report a problem (take it as a suggestion of improvement) about Kotlin optionals in Swift.
Let’s take the example of a Kotlin Long
. If I write a method taking one as a parameter, I have a native conversion to Int64
:
fun test(param: Long) {}
Is mapped to
func test(param: Int64) {}
And so I can call it by passing a Int64
directly, or when I implement an Kotlin interface from Swift handle it as an Int64
.
But now, let’s take the same example with an optional (so Long?
):
fun test(param: Long?) {}
Is mapped to
func test(param: KotlinLong?) {}
So when I call the function I need to make a KotlinLong(value: myInt64)
inside a check to know if it is not nil
. And when I implement an interface (less annoying), I need to use param?.int64value
to use it.
I also encountered a similar behavior with String?
where I had to add a as NSString
everywhere I call a Kotlin function was expecting an optional string.
Is there any change that can be made on the compiler to handle optionals like non optionals types?