Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReactiveCompatible is a class protocol in RxSwift 6 #2270

Closed
6 of 9 tasks
groue opened this issue Jan 3, 2021 · 6 comments
Closed
6 of 9 tasks

ReactiveCompatible is a class protocol in RxSwift 6 #2270

groue opened this issue Jan 3, 2021 · 6 comments

Comments

@groue
Copy link

groue commented Jan 3, 2021

Short description of the issue:

ReactiveCompatible is a class-only protocol in RxSwift 6, which prevents declaring handy .rx extensions on structs. This affects the RxGRDB repository.

Expected outcome:

ReactiveCompatible can be declared on struct extension, OR there exists another way to declare handy .rx extensions on structs.

What actually happens:

Compiler complains, and I don't know how to manage this breakage.

Self contained code example that reproduces the issue:

// No longer compiles
protocol P { ... }
struct S: P { ... }
extension S: ReactiveCompatible { } // Non-class type 'S' cannot conform to class protocol 'ReactiveCompatible'
extension Reactive where Base: P { /* handy extensions */ }

let s = S(...)
s.rx.yeah()

RxSwift/RxCocoa/RxBlocking/RxTest version/commit

RxSwift 6.0.0

Platform/Environment

  • iOS
  • macOS
  • tvOS
  • watchOS
  • playgrounds

How easy is to reproduce? (chances of successful reproduce after running the self contained code)

  • easy, 100% repro
  • sometimes, 10%-100%
  • hard, 2% - 10%
  • extremely hard, %0 - 2%

Xcode version:

Version 12.3 (12C33)
@freak4pc
Copy link
Member

freak4pc commented Jan 3, 2021

Hey @groue - Thanks for reporting :)
This is a breaking change and a known downside of the new @dynamicMemberLookup approach we took for RxSwift 6.

Luckily, you can make a wrapper to resolve this issue:

struct MyObject { } 

extension MyObject {
    struct Rx { 
        private let base: MyObject
        init(_ base: MyObject) { self.base = base }
    }
}

public extension MyObject.Rx { 
    /// Reactive extensions
}

Everything else can remain as-is.

Does this solution accommodate that specific use-case?

@groue
Copy link
Author

groue commented Jan 3, 2021

Thanks for your help and explanation 👍 !

I have too many structs to extend, so I'll basically have to restore the old Reactive struct-compatible wrapper. Now I'm just struggling to find a distinct name so that it does not conflict with RxSwift's ;-)

I'll close this issue. Maybe, if several users report similar problems, this breaking change will turn into a regression that deserves to be addressed.

@groue groue closed this as completed Jan 3, 2021
@iDevid
Copy link
Contributor

iDevid commented Jan 15, 2021

I also find myself using ReactiveCompatible with many models that are structs

@bigMOTOR
Copy link

bigMOTOR commented Feb 1, 2021

So do I.

@freak4pc
Copy link
Member

@groue @bigMOTOR - Thanks to @iDevid's creative solution, RxSwift 6.1 (coming out today) will bring back non-Class support.

Thanks again!

@freak4pc
Copy link
Member

RxSwift 6.1 is out with this fix. Thanks @iDevid! Let me know if this helps your cases @groue @bigMOTOR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants