From afe12623221f987bf898f9ad9c34be63fb584379 Mon Sep 17 00:00:00 2001 From: Marat Al Date: Thu, 26 Sep 2024 18:14:04 +0200 Subject: [PATCH] Conditional using of `@retroactive` attribute for Xcode 16. --- Test/Test Utilities/TestUtilities.swift | 40 ++++++++++++++++++++ Test/Tests/RealtimeClientChannelsTests.swift | 9 +++++ Test/Tests/RestClientChannelsTests.swift | 8 ++++ 3 files changed, 57 insertions(+) diff --git a/Test/Test Utilities/TestUtilities.swift b/Test/Test Utilities/TestUtilities.swift index 09bb0ddac..a7e3a1b7d 100644 --- a/Test/Test Utilities/TestUtilities.swift +++ b/Test/Test Utilities/TestUtilities.swift @@ -1777,6 +1777,44 @@ extension ARTMessage { } } +#if hasFeature(RetroactiveAttribute) +extension ARTRealtimeConnectionState : @retroactive CustomStringConvertible { + public var description : String { + return ARTRealtimeConnectionStateToStr(self) + } +} + +extension ARTRealtimeConnectionEvent : @retroactive CustomStringConvertible { + public var description : String { + return ARTRealtimeConnectionEventToStr(self) + } +} + +extension ARTProtocolMessageAction : @retroactive CustomStringConvertible { + public var description : String { + return ARTProtocolMessageActionToStr(self) + } +} + +extension ARTRealtimeChannelState : @retroactive CustomStringConvertible { + public var description : String { + return ARTRealtimeChannelStateToStr(self) + } +} + +extension ARTChannelEvent : @retroactive CustomStringConvertible { + public var description : String { + return ARTChannelEventToStr(self) + } +} + +extension ARTPresenceAction : @retroactive CustomStringConvertible { + public var description : String { + return ARTPresenceActionToStr(self) + } +} + +#else extension ARTRealtimeConnectionState : CustomStringConvertible { public var description : String { @@ -1814,6 +1852,8 @@ extension ARTPresenceAction : CustomStringConvertible { } } +#endif + // MARK: - Custom Nimble Matchers /// A Nimble matcher that succeeds when two dates are quite the same. diff --git a/Test/Tests/RealtimeClientChannelsTests.swift b/Test/Tests/RealtimeClientChannelsTests.swift index 7cb29daa3..4c63cb583 100644 --- a/Test/Tests/RealtimeClientChannelsTests.swift +++ b/Test/Tests/RealtimeClientChannelsTests.swift @@ -2,12 +2,21 @@ import Ably import Nimble import XCTest +#if hasFeature(RetroactiveAttribute) +// Swift isn't yet smart enough to do this automatically when bridging Objective-C APIs +extension ARTRealtimeChannels: @retroactive Sequence { + public func makeIterator() -> NSFastEnumerationIterator { + return NSFastEnumerationIterator(iterate()) + } +} +#else // Swift isn't yet smart enough to do this automatically when bridging Objective-C APIs extension ARTRealtimeChannels: Sequence { public func makeIterator() -> NSFastEnumerationIterator { return NSFastEnumerationIterator(iterate()) } } +#endif class RealtimeClientChannelsTests: XCTestCase { // RTS2 diff --git a/Test/Tests/RestClientChannelsTests.swift b/Test/Tests/RestClientChannelsTests.swift index fb24fd945..2356fed95 100644 --- a/Test/Tests/RestClientChannelsTests.swift +++ b/Test/Tests/RestClientChannelsTests.swift @@ -2,12 +2,20 @@ import Ably import Nimble import XCTest +#if hasFeature(RetroactiveAttribute) // Swift isn't yet smart enough to do this automatically when bridging Objective-C APIs +extension ARTRestChannels: @retroactive Sequence { + public func makeIterator() -> NSFastEnumerationIterator { + return NSFastEnumerationIterator(iterate()) + } +} +#else extension ARTRestChannels: Sequence { public func makeIterator() -> NSFastEnumerationIterator { return NSFastEnumerationIterator(iterate()) } } +#endif private func beAChannel(named expectedValue: String) -> Nimble.Predicate { return Predicate.define("be a channel with name \"\(expectedValue)\"") { actualExpression, msg -> PredicateResult in