Fixes some test failures and warnings with Swift 5.9.
JSONEncoding appears to be non-deterministic with Swift 5.9; add JSONEncoder.sorted member using JSONEncoder.OutputFormatting.sortedKeys and use that in tests and in CodableRequestContainer
Add RequestCache.decoder and .encoder members and use those rather than initializing new instances when needed. This allows using sorted keys when testing.
Add UserManagerMock.cast() method to handle failure when casting types when optional members are nil (see below for details)
Fix warning about unhandled UIUserInterfaceIdiom.reality case in its .description member
About that UserManagerMock.cast() Method
A minimal demonstration of the crash this method addresses. It only affects test code, not the SDK itself, and is visible when using Xcode 15.0b1 to test on iOS 17.0 but not when using it to test on iOS 16.4 (so it doesn't seem to be a Swift 5.9 thing):
extension Never: Codable {
public func encode(to encoder: Encoder) throws {
// no-op
}
public init(from decoder: Decoder) throws {
throw DecodingError.valueNotFound(...)
}
}
struct UserUpdate<I: Encodable, A: Encodable>: Encodable {
var identifiers: I?
var attributes: A?
}
func safeCast<I: Encodable, A: Encodable>(_ update: UserUpdate<I, A>) {
_ = update as! UserUpdate<Int, Int>
}
func unsafeCast<I: Encodable, A: Encodable>(_ update: UserUpdate<I, A>) {
_ = update as! UserUpdate<Never, Int> // Ok on iOS <= 16.x; crash on iOS 17
}
let u1 = UserUpdate<Int, Int>(identifiers: nil, attributes: 5)
safeCast(u1) // no problems
let u2 = UserUpdate<Never, Int>(identifiers: nil, attributes: 5)
_ = u2 as! UserUpdate<Never, Int> // no problems
unsafeCast(u2) // problems
Fixes some test failures and warnings with Swift 5.9.
JSONEncoder.sorted
member usingJSONEncoder.OutputFormatting.sortedKeys
and use that in tests and inCodableRequestContainer
RequestCache.decoder
and.encoder
members and use those rather than initializing new instances when needed. This allows using sorted keys when testing.UserManagerMock.cast()
method to handle failure when casting types when optional members arenil
(see below for details)UIUserInterfaceIdiom.reality
case in its.description
memberAbout that
UserManagerMock.cast()
MethodA minimal demonstration of the crash this method addresses. It only affects test code, not the SDK itself, and is visible when using Xcode 15.0b1 to test on iOS 17.0 but not when using it to test on iOS 16.4 (so it doesn't seem to be a Swift 5.9 thing):