Skip to content

Update combineIdentifier implementation on non-ObjectiveC platform #18

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

Merged
merged 1 commit into from
Dec 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions Sources/OpenCombine/Publishers/Publishers.CombineLatest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,14 @@ extension AbstractCombineLatest {
struct Side<Input> {
let index: Int
let combiner: AbstractCombineLatest

// `CombineIdentifier(AbstractCombineLatest.self)` will cause build fail on non-ObjC platform
// Even we can make trick to compile successfully by using `CombineIdentifier(AbstractCombineLatest.self as AnyObject)`
// The runtime behavior is still not correct and may give different result here.
// Tracked by https://github.com/apple/swift/issues/70645
#if !canImport(ObjectiveC)
let combineIdentifier = CombineIdentifier()
#endif

init(index: Int, combiner: AbstractCombineLatest) {
self.index = index
self.combiner = combiner
Expand All @@ -652,13 +659,17 @@ extension AbstractCombineLatest {
}

extension AbstractCombineLatest.Side: Subscriber {
// `CombineIdentifier(AbstractCombineLatest.self)` will cause build fail on non-ObjC platform
// Even we can make trick to compile successfully by using `CombineIdentifier(AbstractCombineLatest.self as AnyObject)`
// The runtime behavior is still not correct and may give different result here.
// Tracked by https://github.com/apple/swift/issues/70645
#if canImport(ObjectiveC)
// NOTE: Audited with Combine 2023 release.
// A better implementation is `let combineIdentifier = CombineIdentifier()` IMO.
var combineIdentifier: CombineIdentifier {
// `CombineIdentifier(AbstractCombineLatest.self) will cause build fail on non-Darwin platform
// Tracked by https://github.com/apple/swift/issues/70645
CombineIdentifier(AbstractCombineLatest.self as AnyObject)
CombineIdentifier(AbstractCombineLatest.self)
}
#endif

func receive(subscription: Subscription) {
combiner.receive(subscription: subscription, index: index)
Expand Down