From 7300e372649af9b5f210b1ff223dbac5b77b811e Mon Sep 17 00:00:00 2001 From: Kyle Date: Sat, 30 Dec 2023 12:01:59 +0800 Subject: [PATCH] Update combineIdentifier implementation on non-ObjectiveC platform --- .../Publishers/Publishers.CombineLatest.swift | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/Sources/OpenCombine/Publishers/Publishers.CombineLatest.swift b/Sources/OpenCombine/Publishers/Publishers.CombineLatest.swift index f8082ad2..f1ed4a3a 100644 --- a/Sources/OpenCombine/Publishers/Publishers.CombineLatest.swift +++ b/Sources/OpenCombine/Publishers/Publishers.CombineLatest.swift @@ -643,7 +643,14 @@ extension AbstractCombineLatest { struct Side { 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 @@ -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)