RxSwift: Name Conflict from Xcode 15

Short description of the issue: Since introduction of Observation framework, importing both RxSwift and Observation arises name conflict

Expected outcome:

compile without error

What actually happens:

compile error

Protocol 'Observable' does not have primary associated types that can be constrained

Self contained code example that reproduces the issue:

import SwiftUI
import RxSwift

struct ContentView: View {
    var body: some View {
        Color.black
    }

    func observable() -> Observable<Int> { // Protocol 'Observable' does not have primary associated types that can be constrained
        .just(1)
    }
}

RxSwift/RxCocoa/RxBlocking/RxTest version/commit

6.6.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:

Xcode 15 developer beta 2

⚠️ Fields below are optional for general issues or in case those questions aren’t related to your issue, but filling them out will increase the chances of getting your issue resolved. ⚠️

Installation method:

  • CocoaPods
  • Carthage
  • Git submodules
  • Swift Package Manager

I have multiple versions of Xcode installed: (so we can know if this is a potential cause of your issue)

  • yes (which ones)
  • no

Level of RxSwift knowledge: (this is so we can understand your level of knowledge and formulate the response in an appropriate manner)

  • just starting
  • I have a small code base
  • I have a significant code base

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 2
  • Comments: 24 (12 by maintainers)

Commits related to this issue

Most upvoted comments

still an issue in beta 8 for me.

The same is affecting the Observable extensions in RxSwiftExt (like https://github.com/RxSwiftCommunity/RxSwiftExt/blob/main/Source/RxSwift/distinct.swift#L27) Screenshot 2023-08-09 at 17 35 09

The RxSwiftExt issue specifically was resolved in RxSwiftExt 6.2.0.

I had this problem in Xcode15 beta 4, then it was fixed (?) in Xcode 15 beta 5, but now it is back again in Xcode beta 6.

But I found something curious:

extension Observable {
    static func unimplemented(file: String = #file, function: String = #function, line: Int = #line)
        -> Observable<Element> { // Error does not happen here
        unimplementedFunction(file: file, function: function, line: line)
            return Observable<Element>.empty()  // <-- Error only happens here
    }
}

This error only seems to apply to return statements in my project. If I remove the Observable<Element> from the return statement so it becomes only .empty() and let the compiler infer the type, it works. It also works with just Observable.empty(). Not sure if this helps or not.

I’m closing this thread for now, seems like indeed this is fixed. If anything changes, feel free to comment here.

That’s interesting, the protocol is still there. For our huge codebase it also seems to work, but I had to import RxSwift in a single file where just doing import RxCocoa wasn’t enough for some reason.

It seems resolved in Xcode 15 beta 5.

Some more things I noticed that seem to work a bit better then before (In Xcode 15 Beta 4).

  1. In a specific file where I had SwiftUI & RxSwift imported, i removed the SwiftUI import and it knew to take the right Observable even though SwiftUI is imported in other places in the module.
  2. In my main app adding a public typealias Observable = RxSwift.Observable in some central place seems to work with a single statement. It didn’t solve the issue in previous betas.

Seems that between this and the option to rename everything to RxObservable, this will be an annoying breaking change, but one with a few possible solutions, depending on the codebase.

These are all the changes I had to do to get my entire project to compile, and we have about 50 modules: image

A workaround to this issue is to declare a typealias of Observable inside the modules you are experiencing issues:

import RxSwift

// Needed to disambiguate between Foundation's Observable and RxSwift's Observable
typealias Observable = RxSwift.Observable

This shouldn’t be needed in a future release: https://forums.swift.org/t/pitch-observation-revised/63757/98