Skip to content

Commit

Permalink
Merge pull request #1978 from ably/fix/1977-xcode16-analyzer-issues
Browse files Browse the repository at this point in the history
[ECO-4999] Preparing for use with Xcode 16
  • Loading branch information
maratal authored Sep 30, 2024
2 parents cb3f23d + afe1262 commit 63e6f00
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Source/ARTDataEncoder.m
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ - (ARTDataEncoderOutput *)encode:(id)data {
encoded = [data dataUsingEncoding:NSUTF8StringEncoding];
encoding = [NSString artAddEncoding:@"utf-8" toString:encoding];
}
if (encoded == nil) {
return [[ARTDataEncoderOutput alloc] initWithData:data encoding:nil errorInfo:[ARTErrorInfo createWithCode:0 message:@"must be NSString, NSData, NSArray or NSDictionary."]];
}
ARTStatus *status = [_cipher encrypt:encoded output:&toBase64];
if (status.state != ARTStateOk) {
ARTErrorInfo *errorInfo = status.errorInfo ? status.errorInfo : [ARTErrorInfo createWithCode:0 message:@"encrypt failed"];
Expand Down Expand Up @@ -181,7 +184,7 @@ - (ARTDataEncoderOutput *)decode:(id)data identifier:(NSString *)identifier enco
if (status.state != ARTStateOk) {
errorInfo = status.errorInfo ? status.errorInfo : [ARTErrorInfo createWithCode:ARTErrorInvalidMessageDataOrEncoding message:@"decrypt failed"];
}
} else if ([encoding isEqualToString:@"vcdiff"] && _deltaCodec) {
} else if ([encoding isEqualToString:@"vcdiff"] && _deltaCodec && [data isKindOfClass:[NSData class]]) {
NSError *decodeError;
data = [_deltaCodec applyDelta:data deltaId:identifier baseId:_baseId error:&decodeError];

Expand Down
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 63e6f00

Please sign in to comment.