rbrn
rbrn

Reputation: 55

How to use RxSwift in project with Objective-C code?

I am working in a old project that mixes Objective-C and Swift, there is a lot of legacy code in Objective-C, so migrating everything to Swift is not realistic. New code is written in Swift but Objective-C needs to be mantained with small updates.

And I have been working with RxSwift recently and I want to start using in this old project too.

The problem is the Objective-C <-> Swift interoperability.

e.g. I can't write this:

@objc let int = BehaviorSubject<Int>(value: 42)

Because I get Property cannot be marked @objc because its type cannot be represented in Objective-C

How can I deal with this situation? Is anyone using RxSwift in a mixed objc/swift project?

Upvotes: 2

Views: 1068

Answers (1)

Daniel T.
Daniel T.

Reputation: 33967

The core of RxSwift is the Event enum with associated values. This enum cannot be ported into Objective-C.

The answer to your question is... You can't use RxSwift in Objective-C code.

An alternative would be use ReactiveObjC in your Objective-C code and map from RxSwift Observables to ReactiveObjC Signals.

Upvotes: 2

Related Questions