Kotlin-native: Unit bridges to KotlinUnit in Swift escaping closures

Created on 17 Jan 2019  路  5Comments  路  Source: JetBrains/kotlin-native

For functions/closures that return KotlinUnit in Swift, you get a warning about an unused result, which isn't ideal.

In kotlin, this return type is used as Void in Swift (void in C/Obj-C). I'm having trouble locating such an attribute, but ideally there'd be a way to attribute this return value in the Obj-C header as discardable (i.e. the @discardableResult Obj-C equivalent). If there are other ways to improve this situation, those would also be nice. Thanks!

Most helpful comment

It is indeed a hard sell to iOS developers in my company and might not be taken seriously just because it adds noise.

All 5 comments

Actually, this might be a bug? According to the interop doc, unit should bridge to void: https://kotlinlang.org/docs/reference/native/objc_interop.html

This is still the case in K/N 1.3.21, would be great if one could just return Void in Swift instead of the unnecessary KotlinUnit currently.

Unfortunately, the function types section specifically mentions that function types are treated different than regular functions and seems intentional.

We are developing a library and the fact that we have to leak to users of our library that we are using Kotlin under the hood is not very nice. Not to speak of the fact that people are forced to type return KotlinUnit() for every call.

It is indeed a hard sell to iOS developers in my company and might not be taken seriously just because it adds noise.

Improved with #2968. Will likely be shipped within 1.3.40.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

9468305 picture 9468305  路  3Comments

dpomada picture dpomada  路  3Comments

benasher44 picture benasher44  路  4Comments

talanov picture talanov  路  3Comments

AregevDev picture AregevDev  路  3Comments