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
- Introduce a RxObservable typealias to workaround SE-0395 conflict In Swift 5.9 / Xcode 15 beta 2, Apple introduced a re-export of its own protocol called Observable, under the Observation framework. ... — committed to ReactiveX/RxSwift by freak4pc a year ago
- Introduce a RxObservable typealias to workaround SE-0395 conflict In Swift 5.9 / Xcode 15 beta 2, Apple introduced a re-export of its own protocol called Observable, under the Observation framework. ... — committed to GalBerezansky/RxSwift by freak4pc a year ago
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)
The RxSwiftExt issue specifically was resolved in RxSwiftExt 6.2.0.
https://github.com/apple/swift/issues/67815
I opened an issue about it
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:
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 justObservable.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 doingimport 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).
SwiftUI
is imported in other places in the module.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:
A workaround to this issue is to declare a
typealias
of Observable inside the modules you are experiencing issues:This shouldn’t be needed in a future release: https://forums.swift.org/t/pitch-observation-revised/63757/98