Skip to content

Commit

Permalink
Conditional using of @retroactive attribute for Xcode 16.
Browse files Browse the repository at this point in the history
  • Loading branch information
maratal committed Sep 26, 2024
1 parent 821f9f2 commit afe1262
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
40 changes: 40 additions & 0 deletions Test/Test Utilities/TestUtilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -1814,6 +1852,8 @@ extension ARTPresenceAction : CustomStringConvertible {
}
}

#endif

// MARK: - Custom Nimble Matchers

/// A Nimble matcher that succeeds when two dates are quite the same.
Expand Down
9 changes: 9 additions & 0 deletions Test/Tests/RealtimeClientChannelsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions Test/Tests/RestClientChannelsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<ARTChannel> {
return Predicate.define("be a channel with name \"\(expectedValue)\"") { actualExpression, msg -> PredicateResult in
Expand Down

0 comments on commit afe1262

Please sign in to comment.