question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Provide a non-null type constraint for better interop with swift

See original GitHub issue

Due to constraints related to how obj-c and swift handle nullable types, generic type parameters from kotlin get converted into nullable types unless they have a non-null constraint:

image

Reaktive suffers from the same problem: its value callbacks receive a nullable types:

image

Will it be possible to make this change in ValueCallback?

interface ValueCallback<in T : Any> {

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (9 by maintainers)

github_iconTop GitHub Comments

3reactions
arkivanovcommented, May 1, 2020

Working on this currently. I still think that one non-null ObservableWrapper<out T : Any> will be better than two nullable and non-null. My points:

  1. Nullable cases are rare, we mostly use non-null types (we also have Maybe that helps a lot)
  2. If a user needs additional operators e.g. map they can extend just one class ObservableWrapper and add whatever needed. If there are two classes then the complexity may grow up to 4 times.
  3. If there is a strong need to expose non-null types to Swift then something like a simple Optional may be used instead
  4. We could provide overloaded subscribe methods only for one class instead of two

Overall I believe it is better to have solid and non-confusing API for most of the cases.

@mk-jones @CherryPerry @saket Waiting for your opinions!

2reactions
mike-n-jordancommented, Apr 29, 2020

@arkivanov Perhaps something like a NonNullObservableWrapper<T: Any>? So the user can choose how we communicate the type to swift.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Interoperability with Swift/Objective-C - Kotlin
Kotlin/Native provides bidirectional interoperability with Objective-C. ... type should never be null, provide a non-null type constraint:.
Read more >
Kotlin Native Interop Generics - Medium
As mentioned, however, if your Kotlin code defines a non-null constraint on a type, Objc will have non-null method/property declarations, ...
Read more >
Using generic type constraints in Swift | Swift by Sundell
Using generic type constraints, we are able to add new APIs and behaviors to a type only under a certain set of constraints....
Read more >
Understanding null safety - Dart
To express that, we give dairy a nullable type by slapping ? at the end of the underlying ... In cases where the...
Read more >
Native - Objective-C and Swift Interop - 《Kotlin Language Guide v1 ...
Kotlin/Native interoperability with Swift/Objective-CUsageMappingsName ... if the generic type should never be null, provide a non-null type constraint:
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found