Has anyone tried to use RxSwift or RxJava with a K...
# kotlin-native
y
Has anyone tried to use RxSwift or RxJava with a Kotlin Native project? It’s a requirement for the multiplatform project I’m working on. Am I right in thinking that the common code (written in K/N) will invoke the relevant RxSwift/RxJava code through an interface/protocol? The RxJava code could be written in K/N too, but it’s the RxSwift code that will be the problem as that will have to be written in Swift.
t
Not really, but here are my thoughts about that: Your
common
code cannot depend on any platform specific library like
RxJava
or
RxSwift
. In case you need to reference this code from your
common
module you have for now these choices: 1. Using
expect
and
actual
keywords from the multiplatform feature Declaring an
expect
class in the
common
module forces you to provide an
actual
implementation written in kotlin for each platform. You can either use the kotlin stdlib or the interoperability feature to fulfill this contract on the
ios
module. The interoperability feature allows you to call any native library from kotlin. If
RxSwift
is a native library this might be an option. 2. Use interfaces Alternatively you could declare and use an
interface
in the
common
module to model the async part. This interface will be then compiled to a
protocol
which you then can implement in swift. A pure kotlin implementation of rxjava would be great. Or even better a common reactive api for multiple platforms: https://github.com/JakeWharton/Reagent
y
thanks a lot for this! RxSwift isn’t a native library so I guess we will go with option 2
👍 1