From 47b0a3b174b6b440f07b07467e85f3a67c2325b8 Mon Sep 17 00:00:00 2001 From: Corey Date: Mon, 24 Jun 2024 12:38:04 -0700 Subject: [PATCH] ci: Update Xcode to 15.4 (#166) * ci: Update Xcode to 15.3 * Update release.yml * Update ci.yml * Update ci.yml * fix test host for xrsimulator * add visionOS to targeted devices * Update ci.yml * Update ci.yml * install SwiftLint * Update release.yml * Update ci.yml * fix swiftlint non_optional_string_data_conversion * revert ParseTypeable description due to failures * dont test some tests on tvOS * set OS version of iOS, tvOS, and visionOS * fix omitted tests in matrix * remove visionOS test for now --- .github/workflows/ci.yml | 28 +++++----- .github/workflows/release.yml | 6 +-- .swiftlint.yml | 1 + .../9 - Files.xcplaygroundpage/Contents.swift | 4 +- ParseSwift.xcodeproj/project.pbxproj | 14 +++-- Sources/ParseSwift/API/API.swift | 8 +-- .../3rd Party/ParseApple/ParseApple.swift | 4 +- Sources/ParseSwift/Coding/AnyCodable.swift | 2 +- Sources/ParseSwift/Coding/AnyEncodable.swift | 2 +- Sources/ParseSwift/Coding/ParseCoding.swift | 3 +- Sources/ParseSwift/Extensions/Encodable.swift | 9 ++-- .../ParseSwift/Extensions/URLSession.swift | 3 +- .../LiveQuery/LiveQuerySocket.swift | 10 +--- .../ParseSwift/LiveQuery/ParseLiveQuery.swift | 2 +- Sources/ParseSwift/Objects/ParseObject.swift | 5 +- Sources/ParseSwift/Protocols/Objectable.swift | 4 +- .../ParseSwift/Protocols/ParseEncodable.swift | 5 +- .../Protocols/ParseOperationable.swift | 7 ++- .../ParseSwift/Protocols/ParseTypeable.swift | 7 ++- Sources/ParseSwift/Types/ParseError.swift | 2 +- .../ParseSwift/Types/ParseFieldOptions.swift | 7 ++- Sources/ParseSwift/Types/ParseFile.swift | 4 +- Sources/ParseSwift/Types/ParseOperation.swift | 7 ++- Sources/ParseSwift/Types/Query.swift | 19 ++++--- Tests/ParseSwiftTests/IOS13Tests.swift | 2 +- .../ParseSwiftTests/ParseAnalyticsTests.swift | 2 +- .../ParseSwiftTests/ParseFileAsyncTests.swift | 10 ++-- .../ParseHookFunctionRequestTests.swift | 5 +- .../ParseSwiftTests/ParseLiveQueryTests.swift | 26 +++++----- .../ParseObjectBatchTests.swift | 10 ++-- .../ParseObjectCustomObjectIdTests.swift | 24 ++++----- Tests/ParseSwiftTests/ParseObjectTests.swift | 6 +-- .../ParseSwiftTests/ParseOperationTests.swift | 52 +++++++++---------- Tests/ParseSwiftTests/ParsePointerTests.swift | 4 +- Tests/ParseSwiftTests/ParsePushTests.swift | 8 +-- Tests/ParseSwiftTests/ParseQueryTests.swift | 46 ++++++---------- .../ParseSwiftTests/ParseRelationTests.swift | 48 ++++++++--------- Tests/ParseSwiftTests/ParseRoleTests.swift | 24 ++++----- Tests/ParseSwiftTests/ParseSessionTests.swift | 4 +- 39 files changed, 191 insertions(+), 243 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a495d685b..94c280622 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,7 +10,7 @@ on: env: CI_XCODE_OLDEST: '/Applications/Xcode_13.3.1.app/Contents/Developer' CI_XCODE_14: '/Applications/Xcode_14.3.1.app/Contents/Developer' - CI_XCODE_LATEST: '/Applications/Xcode_15.2.app/Contents/Developer' + CI_XCODE_LATEST: '/Applications/Xcode_15.4.app/Contents/Developer' concurrency: group: ${{ github.workflow }}-${{ github.ref }} @@ -19,26 +19,26 @@ concurrency: jobs: test: timeout-minutes: 25 - runs-on: macos-13 + runs-on: macos-14 strategy: matrix: - destination: ['platform=iOS\ Simulator,name=iPhone\ 15\ Pro\ Max', 'platform\=tvOS\ Simulator,name\=Apple\ TV', 'platform=watchOS\ Simulator,name=Apple\ Watch\ Series\ 9\ \(41mm\)', 'platform=visionOS\ Simulator,name=Apple\ Vision\ Pro', 'platform=macOS'] + destination: ['platform=iOS\ Simulator,OS=17.5,name=iPhone\ 15\ Pro\ Max', 'platform\=tvOS\ Simulator,OS=17.5,name\=Apple\ TV', 'platform=watchOS\ Simulator,name=Apple\ Watch\ Series\ 9\ \(41mm\)', 'platform=macOS'] # 'platform=visionOS\ Simulator,OS=1.2,name=Apple\ Vision\ Pro' action: ['test', 'build'] exclude: - - destination: 'platform=iOS\ Simulator,name=iPhone\ 15\ Pro\ Max' + - destination: 'platform=iOS\ Simulator,OS=17.5,name=iPhone\ 15\ Pro\ Max' action: 'build' - - destination: 'platform\=tvOS\ Simulator,name\=Apple\ TV' + - destination: 'platform\=tvOS\ Simulator,OS=17.5,name\=Apple\ TV' action: 'build' - destination: 'platform=macOS' action: 'build' - - destination: 'platform=visionOS\ Simulator,name=Apple\ Vision\ Pro' - action: 'build' + # - destination: 'platform=visionOS\ Simulator,OS=1.2,name=Apple\ Vision\ Pro' + # action: 'build' - destination: 'platform=watchOS\ Simulator,name=Apple\ Watch\ Series\ 9\ \(41mm\)' action: 'test' steps: - uses: actions/checkout@v4 - - name: Use multiple cores - run: defaults write com.apple.dt.XCBuild EnableSwiftBuildSystemIntegration 1 + - name: Install SwiftLint + run: brew install swiftlint - name: Create and set the default keychain run: | security create-keychain -p "" temporary @@ -77,8 +77,8 @@ jobs: security default-keychain -s temporary security unlock-keychain -p "" temporary security set-keychain-settings -lut 7200 temporary - - name: Use multiple cores - run: defaults write com.apple.dt.XCBuild EnableSwiftBuildSystemIntegration 1 + - name: Install SwiftLint + run: brew install swiftlint - name: Build-Test run: set -o pipefail && env NSUnbufferedIO=YES swift test --enable-code-coverage | xcpretty -c env: @@ -131,7 +131,7 @@ jobs: uses: codecov/codecov-action@v4 with: env_vars: LINUX - fail_ci_if_error: false + fail_ci_if_error: true token: ${{ secrets.CODECOV_TOKEN }} windows: @@ -159,8 +159,6 @@ jobs: runs-on: macos-14 steps: - uses: actions/checkout@v4 - - name: Use multiple cores - run: defaults write com.apple.dt.XCBuild EnableSwiftBuildSystemIntegration 1 - name: Generate Docs run: set -o pipefail && env NSUnbufferedIO=YES Scripts/generate-documentation env: @@ -171,8 +169,6 @@ jobs: runs-on: macos-14 steps: - uses: actions/checkout@v4 - - name: Use multiple cores - run: defaults write com.apple.dt.XCBuild EnableSwiftBuildSystemIntegration 1 - name: Update Framework Version run: ./Scripts/update_build env: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 92d38ffaf..eb211ec90 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -4,7 +4,7 @@ on: types: [published] env: CI_XCODE_14: '/Applications/Xcode_14.3.1.app/Contents/Developer' - CI_XCODE_LATEST: '/Applications/Xcode_15.2.app/Contents/Developer' + CI_XCODE_LATEST: '/Applications/Xcode_15.4.app/Contents/Developer' jobs: cocoapods: @@ -13,8 +13,6 @@ jobs: - uses: actions/checkout@v4 - name: Get release version run: echo "TAG=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV - - name: Use multiple cores - run: defaults write com.apple.dt.XCBuild EnableSwiftBuildSystemIntegration 1 - name: Update Framework Version run: ./Scripts/update_build env: @@ -31,8 +29,6 @@ jobs: - uses: actions/checkout@v4 - name: Get release version run: echo "TAG=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV - - name: Use multiple cores - run: defaults write com.apple.dt.XCBuild EnableSwiftBuildSystemIntegration 1 - name: Build and Deploy Docs run: set -o pipefail && env NSUnbufferedIO=YES Scripts/update-gh-pages-documentation-site env: diff --git a/.swiftlint.yml b/.swiftlint.yml index 7d412701d..bc875a404 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -2,6 +2,7 @@ disabled_rules: - file_length - identifier_name - blanket_disable_command + - non_optional_string_data_conversion excluded: # paths to ignore during linting. Takes precedence over `included`. - Tests/ParseSwiftTests/ParseEncoderTests - DerivedData diff --git a/ParseSwift.playground/Pages/9 - Files.xcplaygroundpage/Contents.swift b/ParseSwift.playground/Pages/9 - Files.xcplaygroundpage/Contents.swift index 390e152c8..991c90a21 100644 --- a/ParseSwift.playground/Pages/9 - Files.xcplaygroundpage/Contents.swift +++ b/ParseSwift.playground/Pages/9 - Files.xcplaygroundpage/Contents.swift @@ -194,9 +194,7 @@ Task { assertionFailure("Data is not the same. Something went wrong.") } - guard let parseFileString = String(data: dataFromParseFile, encoding: .utf8) else { - fatalError("Error: Could not create String from data.") - } + let parseFileString = String(decoding: dataFromParseFile, as: UTF8.self) print("The data saved on parse is: \"\(parseFileString)\"") } else { assertionFailure("Error fetching: there should be a localURL") diff --git a/ParseSwift.xcodeproj/project.pbxproj b/ParseSwift.xcodeproj/project.pbxproj index d529806d3..945bd3ec5 100644 --- a/ParseSwift.xcodeproj/project.pbxproj +++ b/ParseSwift.xcodeproj/project.pbxproj @@ -2021,7 +2021,7 @@ SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = YES; SWIFT_SWIFT3_OBJC_INFERENCE = Off; SWIFT_VERSION = 5.0; - TARGETED_DEVICE_FAMILY = "1,2,3,4"; + TARGETED_DEVICE_FAMILY = "1,2,3,4,6,7"; TVOS_DEPLOYMENT_TARGET = 13.0; WATCHOS_DEPLOYMENT_TARGET = 6.0; }; @@ -2056,7 +2056,7 @@ SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = YES; SWIFT_SWIFT3_OBJC_INFERENCE = Off; SWIFT_VERSION = 5.0; - TARGETED_DEVICE_FAMILY = "1,2,3,4"; + TARGETED_DEVICE_FAMILY = "1,2,3,4,6,7"; TVOS_DEPLOYMENT_TARGET = 13.0; WATCHOS_DEPLOYMENT_TARGET = 6.0; }; @@ -2086,7 +2086,7 @@ SUPPORTS_MACCATALYST = YES; SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = YES; SWIFT_VERSION = 5.0; - TARGETED_DEVICE_FAMILY = "1,2,3,4"; + TARGETED_DEVICE_FAMILY = "1,2,3,4,6,7"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/TestHost.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/TestHost"; }; name = Debug; @@ -2115,7 +2115,7 @@ SUPPORTS_MACCATALYST = YES; SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = YES; SWIFT_VERSION = 5.0; - TARGETED_DEVICE_FAMILY = "1,2,3,4"; + TARGETED_DEVICE_FAMILY = "1,2,3,4,6,7"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/TestHost.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/TestHost"; }; name = Release; @@ -2155,12 +2155,11 @@ PRODUCT_BUNDLE_IDENTIFIER = com.parse.TestHost; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = auto; - SUPPORTED_PLATFORMS = "appletvos appletvsimulator iphoneos iphonesimulator macosx watchos"; + SUPPORTED_PLATFORMS = "appletvos appletvsimulator iphoneos iphonesimulator macosx watchos xrsimulator xros"; SUPPORTS_MACCATALYST = NO; SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO; SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_VERSION = 5.0; - TARGETED_DEVICE_FAMILY = "1,2,3"; TVOS_DEPLOYMENT_TARGET = 14.0; WATCHOS_DEPLOYMENT_TARGET = 7.0; }; @@ -2200,12 +2199,11 @@ PRODUCT_BUNDLE_IDENTIFIER = com.parse.TestHost; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = auto; - SUPPORTED_PLATFORMS = "appletvos appletvsimulator iphoneos iphonesimulator macosx watchos"; + SUPPORTED_PLATFORMS = "appletvos appletvsimulator iphoneos iphonesimulator macosx watchos xrsimulator xros"; SUPPORTS_MACCATALYST = NO; SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO; SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_VERSION = 5.0; - TARGETED_DEVICE_FAMILY = "1,2,3"; TVOS_DEPLOYMENT_TARGET = 14.0; WATCHOS_DEPLOYMENT_TARGET = 7.0; }; diff --git a/Sources/ParseSwift/API/API.swift b/Sources/ParseSwift/API/API.swift index 0caf8882b..2ad84e035 100644 --- a/Sources/ParseSwift/API/API.swift +++ b/Sources/ParseSwift/API/API.swift @@ -257,17 +257,17 @@ public struct API { case .removeMimeType: headers.removeValue(forKey: "Content-Type") case .metadata(let metadata): - metadata.forEach {(key, value) -> Void in + metadata.forEach {(key, value) in headers[key] = value } case .tags(let tags): - tags.forEach {(key, value) -> Void in + tags.forEach {(key, value) in headers[key] = value } case .context(let context): let context = AnyEncodable(context) - if let encoded = try? ParseCoding.jsonEncoder().encode(context), - let encodedString = String(data: encoded, encoding: .utf8) { + if let encoded = try? ParseCoding.jsonEncoder().encode(context) { + let encodedString = String(decoding: encoded, as: UTF8.self) headers["X-Parse-Cloud-Context"] = encodedString } default: diff --git a/Sources/ParseSwift/Authentication/3rd Party/ParseApple/ParseApple.swift b/Sources/ParseSwift/Authentication/3rd Party/ParseApple/ParseApple.swift index ff59c6584..4ee71b05c 100644 --- a/Sources/ParseSwift/Authentication/3rd Party/ParseApple/ParseApple.swift +++ b/Sources/ParseSwift/Authentication/3rd Party/ParseApple/ParseApple.swift @@ -30,9 +30,7 @@ public struct ParseApple: ParseAuthentication { /// to a string. func makeDictionary(user: String, identityToken: Data) throws -> [String: String] { - guard let identityTokenString = String(data: identityToken, encoding: .utf8) else { - throw ParseError(code: .otherCause, message: "Could not convert identityToken to String") - } + let identityTokenString = String(decoding: identityToken, as: UTF8.self) return [AuthenticationKeys.id.rawValue: user, AuthenticationKeys.token.rawValue: identityTokenString] } diff --git a/Sources/ParseSwift/Coding/AnyCodable.swift b/Sources/ParseSwift/Coding/AnyCodable.swift index a25f13432..20f8ab831 100755 --- a/Sources/ParseSwift/Coding/AnyCodable.swift +++ b/Sources/ParseSwift/Coding/AnyCodable.swift @@ -73,7 +73,7 @@ extension AnyCodable: Hashable { public func hash(into hasher: inout Hasher) { do { let encodedData = try ParseCoding.jsonEncoder().encode(self) - let encodedString = String(data: encodedData, encoding: .utf8) + let encodedString = String(decoding: encodedData, as: UTF8.self) hasher.combine(encodedString) } catch { hasher.combine(0) diff --git a/Sources/ParseSwift/Coding/AnyEncodable.swift b/Sources/ParseSwift/Coding/AnyEncodable.swift index f5bfe3549..17e0f93b8 100755 --- a/Sources/ParseSwift/Coding/AnyEncodable.swift +++ b/Sources/ParseSwift/Coding/AnyEncodable.swift @@ -192,7 +192,7 @@ extension AnyEncodable: Hashable { public func hash(into hasher: inout Hasher) { do { let encodedData = try ParseCoding.jsonEncoder().encode(self) - let encodedString = String(data: encodedData, encoding: .utf8) + let encodedString = String(decoding: encodedData, as: UTF8.self) hasher.combine(encodedString) } catch { hasher.combine(0) diff --git a/Sources/ParseSwift/Coding/ParseCoding.swift b/Sources/ParseSwift/Coding/ParseCoding.swift index 06b5334dc..0c08a4cdc 100644 --- a/Sources/ParseSwift/Coding/ParseCoding.swift +++ b/Sources/ParseSwift/Coding/ParseCoding.swift @@ -125,8 +125,7 @@ extension ParseCoding { if let decoded = try container.decodeIfPresent(String.self, forKey: .iso), - let date = dateFormatter.date(from: decoded) - { + let date = dateFormatter.date(from: decoded) { return date } else { throw ParseError( diff --git a/Sources/ParseSwift/Extensions/Encodable.swift b/Sources/ParseSwift/Extensions/Encodable.swift index d3e53062b..cda89d65d 100644 --- a/Sources/ParseSwift/Extensions/Encodable.swift +++ b/Sources/ParseSwift/Extensions/Encodable.swift @@ -16,20 +16,17 @@ internal extension Encodable { self, acl: nil ), - let lhsString = String(data: lhsData, encoding: .utf8), let other = other, let rhsData = try? ParseCoding .parseEncoder() .encode( other, acl: nil - ), - let rhsString = String( - data: rhsData, - encoding: .utf8 - ) else { + ) else { return false } + let lhsString = String(decoding: lhsData, as: UTF8.self) + let rhsString = String(decoding: rhsData, as: UTF8.self) return lhsString == rhsString } } diff --git a/Sources/ParseSwift/Extensions/URLSession.swift b/Sources/ParseSwift/Extensions/URLSession.swift index 7e359a786..78cba485c 100644 --- a/Sources/ParseSwift/Extensions/URLSession.swift +++ b/Sources/ParseSwift/Extensions/URLSession.swift @@ -90,8 +90,9 @@ internal extension URLSession { return .failure(ParseError(message: "Error decoding parse-server response: \(response)", swift: error)) } + let errorString = String(decoding: json, as: UTF8.self) // swiftlint:disable:next line_length - return .failure(ParseError(message: "Error decoding parse-server response: \(response) with error: \(String(describing: error)) Format: \(String(describing: String(data: json, encoding: .utf8)))", + return .failure(ParseError(message: "Error decoding parse-server response: \(response) with error: \(String(describing: error)) Format: \(errorString)", swift: error)) } return .failure(parseError) diff --git a/Sources/ParseSwift/LiveQuery/LiveQuerySocket.swift b/Sources/ParseSwift/LiveQuery/LiveQuerySocket.swift index efd941851..32045d385 100644 --- a/Sources/ParseSwift/LiveQuery/LiveQuerySocket.swift +++ b/Sources/ParseSwift/LiveQuery/LiveQuerySocket.swift @@ -57,10 +57,7 @@ extension LiveQuerySocket { .encode(await StandardMessage(operation: .connect, // swiftlint:disable:next line_length additionalProperties: Parse.configuration.liveQueryConnectionAdditionalProperties)) - guard let encodedAsString = String(data: encoded, encoding: .utf8) else { - throw ParseError(code: .otherCause, - message: "Could not encode connect message: \(encoded)") - } + let encodedAsString = String(decoding: encoded, as: UTF8.self) try await task.send(.string(encodedAsString)) await self.receive(task) } @@ -69,10 +66,7 @@ extension LiveQuerySocket { // MARK: Send extension LiveQuerySocket { func send(_ data: Data, task: URLSessionWebSocketTask) async throws { - guard let encodedAsString = String(data: data, encoding: .utf8) else { - throw ParseError(code: .otherCause, - message: "Could not encode data as string: \(data)") - } + let encodedAsString = String(decoding: data, as: UTF8.self) try await task.send(.string(encodedAsString)) } } diff --git a/Sources/ParseSwift/LiveQuery/ParseLiveQuery.swift b/Sources/ParseSwift/LiveQuery/ParseLiveQuery.swift index b1bb856f2..d4c951062 100644 --- a/Sources/ParseSwift/LiveQuery/ParseLiveQuery.swift +++ b/Sources/ParseSwift/LiveQuery/ParseLiveQuery.swift @@ -233,7 +233,7 @@ Not attempting to open ParseLiveQuery socket anymore // Resubscribe to all subscriptions by moving them in front of pending var tempPendingSubscriptions = [(RequestId, SubscriptionRecord)]() let subscriptions = await self.subscriptions.getCurrent() - subscriptions.forEach { (key, value) -> Void in + subscriptions.forEach { (key, value) in tempPendingSubscriptions.append((key, value)) } await self.subscriptions.removeAll() diff --git a/Sources/ParseSwift/Objects/ParseObject.swift b/Sources/ParseSwift/Objects/ParseObject.swift index 9eb742c5c..ccb4e3973 100644 --- a/Sources/ParseSwift/Objects/ParseObject.swift +++ b/Sources/ParseSwift/Objects/ParseObject.swift @@ -721,11 +721,10 @@ transactions for this call. // MARK: CustomDebugStringConvertible extension ParseObject { public var debugDescription: String { - guard let descriptionData = try? ParseCoding.jsonEncoder().encode(self), - let descriptionString = String(data: descriptionData, encoding: .utf8) else { + guard let descriptionData = try? ParseCoding.jsonEncoder().encode(self) else { return "\(className) ()" } - + let descriptionString = String(decoding: descriptionData, as: UTF8.self) return "\(className) (\(descriptionString))" } } diff --git a/Sources/ParseSwift/Protocols/Objectable.swift b/Sources/ParseSwift/Protocols/Objectable.swift index 854380692..da61dfa8d 100644 --- a/Sources/ParseSwift/Protocols/Objectable.swift +++ b/Sources/ParseSwift/Protocols/Objectable.swift @@ -103,9 +103,7 @@ extension Objectable { let encoded = try ParseCoding.parseEncoder().encode(object, acl: nil, batching: false) - guard let hashString = String(data: encoded, encoding: .utf8) else { - throw ParseError(code: .otherCause, message: "Could not create hash") - } + let hashString = String(decoding: encoded, as: UTF8.self) return hashString } diff --git a/Sources/ParseSwift/Protocols/ParseEncodable.swift b/Sources/ParseSwift/Protocols/ParseEncodable.swift index 395350cff..87dbb05b7 100644 --- a/Sources/ParseSwift/Protocols/ParseEncodable.swift +++ b/Sources/ParseSwift/Protocols/ParseEncodable.swift @@ -17,11 +17,10 @@ public protocol ParseEncodable: Encodable {} // MARK: CustomDebugStringConvertible extension ParseEncodable { public var debugDescription: String { - guard let descriptionData = try? ParseCoding.jsonEncoder().encode(self), - let descriptionString = String(data: descriptionData, encoding: .utf8) else { + guard let descriptionData = try? ParseCoding.jsonEncoder().encode(self) else { return "()" } - + let descriptionString = String(decoding: descriptionData, as: UTF8.self) return "\(descriptionString)" } } diff --git a/Sources/ParseSwift/Protocols/ParseOperationable.swift b/Sources/ParseSwift/Protocols/ParseOperationable.swift index eacc9ab3b..9f4081258 100644 --- a/Sources/ParseSwift/Protocols/ParseOperationable.swift +++ b/Sources/ParseSwift/Protocols/ParseOperationable.swift @@ -19,11 +19,10 @@ public protocol ParseOperationable: Codable, // MARK: CustomDebugStringConvertible public extension ParseOperationable { var debugDescription: String { - guard let descriptionData = try? ParseCoding.jsonEncoder().encode(self), - let descriptionString = String(data: descriptionData, encoding: .utf8) else { - return "()" + guard let descriptionData = try? ParseCoding.jsonEncoder().encode(self) else { + return "()" } - + let descriptionString = String(decoding: descriptionData, as: UTF8.self) return "\(descriptionString)" } } diff --git a/Sources/ParseSwift/Protocols/ParseTypeable.swift b/Sources/ParseSwift/Protocols/ParseTypeable.swift index 63f4e40cb..555049652 100644 --- a/Sources/ParseSwift/Protocols/ParseTypeable.swift +++ b/Sources/ParseSwift/Protocols/ParseTypeable.swift @@ -19,11 +19,10 @@ public protocol ParseTypeable: Codable, // MARK: CustomDebugStringConvertible extension ParseTypeable { public var debugDescription: String { - guard let descriptionData = try? ParseCoding.jsonEncoder().encode(self), - let descriptionString = String(data: descriptionData, encoding: .utf8) else { - return "()" + guard let descriptionData = try? ParseCoding.jsonEncoder().encode(self) else { + return "()" } - + let descriptionString = String(decoding: descriptionData, as: UTF8.self) return "\(descriptionString)" } } diff --git a/Sources/ParseSwift/Types/ParseError.swift b/Sources/ParseSwift/Types/ParseError.swift index 93e3789e6..5478f9725 100644 --- a/Sources/ParseSwift/Types/ParseError.swift +++ b/Sources/ParseSwift/Types/ParseError.swift @@ -540,7 +540,7 @@ extension ParseError: LocalizedError { } } -// MARK: +// MARK: Equatable extension ParseError: Equatable { public static func == (lhs: Self, rhs: Self) -> Bool { lhs.code == rhs.code && diff --git a/Sources/ParseSwift/Types/ParseFieldOptions.swift b/Sources/ParseSwift/Types/ParseFieldOptions.swift index 73a7a7e99..b40230a9f 100644 --- a/Sources/ParseSwift/Types/ParseFieldOptions.swift +++ b/Sources/ParseSwift/Types/ParseFieldOptions.swift @@ -43,11 +43,10 @@ extension ParseFieldOptions where V: ParseObject { // MARK: CustomDebugStringConvertible extension ParseFieldOptions { public var debugDescription: String { - guard let descriptionData = try? ParseCoding.jsonEncoder().encode(self), - let descriptionString = String(data: descriptionData, encoding: .utf8) else { - return "()" + guard let descriptionData = try? ParseCoding.jsonEncoder().encode(self) else { + return "()" } - + let descriptionString = String(decoding: descriptionData, as: UTF8.self) return "\(descriptionString)" } } diff --git a/Sources/ParseSwift/Types/ParseFile.swift b/Sources/ParseSwift/Types/ParseFile.swift index 0e7cb1ca5..c33011109 100644 --- a/Sources/ParseSwift/Types/ParseFile.swift +++ b/Sources/ParseSwift/Types/ParseFile.swift @@ -520,10 +520,10 @@ extension ParseFile { // MARK: CustomDebugStringConvertible extension ParseFile: CustomDebugStringConvertible { public var debugDescription: String { - guard let descriptionData = try? ParseCoding.jsonEncoder().encode(self), - let descriptionString = String(data: descriptionData, encoding: .utf8) else { + guard let descriptionData = try? ParseCoding.jsonEncoder().encode(self) else { return "()" } + let descriptionString = String(decoding: descriptionData, as: UTF8.self) return "\(descriptionString)" } } diff --git a/Sources/ParseSwift/Types/ParseOperation.swift b/Sources/ParseSwift/Types/ParseOperation.swift index 1a375911a..804bda361 100644 --- a/Sources/ParseSwift/Types/ParseOperation.swift +++ b/Sources/ParseSwift/Types/ParseOperation.swift @@ -439,11 +439,10 @@ public extension ParseObject { // MARK: CustomDebugStringConvertible public extension ParseOperation { var debugDescription: String { - guard let descriptionData = try? ParseCoding.jsonEncoder().encode(self), - let descriptionString = String(data: descriptionData, encoding: .utf8) else { - return "()" + guard let descriptionData = try? ParseCoding.jsonEncoder().encode(self) else { + return "()" } - + let descriptionString = String(decoding: descriptionData, as: UTF8.self) return "\(descriptionString)" } } diff --git a/Sources/ParseSwift/Types/Query.swift b/Sources/ParseSwift/Types/Query.swift index 07cdac0f0..6c3754d26 100644 --- a/Sources/ParseSwift/Types/Query.swift +++ b/Sources/ParseSwift/Types/Query.swift @@ -73,7 +73,7 @@ public struct Query: ParseTypeable where T: ParseObject { return nil } let encoded = try ParseCoding.jsonEncoder().encode(value) - return String(data: encoded, encoding: .utf8) + return String(decoding: encoded, as: UTF8.self) } } @@ -104,7 +104,7 @@ public struct Query: ParseTypeable where T: ParseObject { return nil } let encoded = try ParseCoding.jsonEncoder().encode(value) - return String(data: encoded, encoding: .utf8) + return String(decoding: encoded, as: UTF8.self) } } @@ -903,8 +903,7 @@ extension Query: Queryable { pipeline.forEach { updatedPipeline = $0.map { [$0.key: AnyCodable($0.value)] } } guard let encoded = try? ParseCoding.jsonEncoder() - .encode(self.`where`), - let whereString = String(data: encoded, encoding: .utf8) else { + .encode(self.`where`) else { let error = ParseError(code: .otherCause, message: "Cannot decode \"where\" to String.") callbackQueue.async { @@ -912,7 +911,7 @@ extension Query: Queryable { } return } - + let whereString = String(decoding: encoded, as: UTF8.self) var query = self query.`where` = QueryWhere() @@ -976,8 +975,7 @@ extension Query: Queryable { pipeline.forEach { updatedPipeline = $0.map { [$0.key: AnyCodable($0.value)] } } guard let encoded = try? ParseCoding.jsonEncoder() - .encode(self.`where`), - let whereString = String(data: encoded, encoding: .utf8) else { + .encode(self.`where`) else { let error = ParseError(code: .otherCause, message: "Cannot decode \"where\" to String.") callbackQueue.async { @@ -986,6 +984,7 @@ extension Query: Queryable { return } + let whereString = String(decoding: encoded, as: UTF8.self) var query = self query.`where` = QueryWhere() @@ -1710,7 +1709,7 @@ internal extension Query { return nil } let encoded = try ParseCoding.jsonEncoder().encode(value) - return String(data: encoded, encoding: .utf8) + return String(decoding: encoded, as: UTF8.self) } func encodeAsString(_ key: KeyPath?>) throws -> String? { @@ -1718,12 +1717,12 @@ internal extension Query { return nil } let encoded = try ParseCoding.jsonEncoder().encode(value) - return String(data: encoded, encoding: .utf8) + return String(decoding: encoded, as: UTF8.self) } func encodeAsString(_ key: KeyPath) throws -> String? where W: Encodable { let encoded = try ParseCoding.jsonEncoder().encode(self[keyPath: key]) - return String(data: encoded, encoding: .utf8) + return String(decoding: encoded, as: UTF8.self) } } // swiftlint:disable:this file_length diff --git a/Tests/ParseSwiftTests/IOS13Tests.swift b/Tests/ParseSwiftTests/IOS13Tests.swift index 662ba7680..e68724bc8 100644 --- a/Tests/ParseSwiftTests/IOS13Tests.swift +++ b/Tests/ParseSwiftTests/IOS13Tests.swift @@ -123,7 +123,7 @@ class IOS13Tests: XCTestCase { .encode(body, collectChildren: false, objectsSavedBeforeThisOne: nil, filesSavedBeforeThisOne: nil).encoded - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } } diff --git a/Tests/ParseSwiftTests/ParseAnalyticsTests.swift b/Tests/ParseSwiftTests/ParseAnalyticsTests.swift index fcdbdebc9..940604072 100644 --- a/Tests/ParseSwiftTests/ParseAnalyticsTests.swift +++ b/Tests/ParseSwiftTests/ParseAnalyticsTests.swift @@ -64,7 +64,7 @@ class ParseAnalyticsTests: XCTestCase { let expected2 = "{\"dimensions\":{\"stop\":\"drop\"},\"name\":\"hello\"}" XCTAssertEqual(decoded2, expected2) let encoded3 = try ParseCoding.parseEncoder().encode(event2) - let decoded3 = String(data: encoded3, encoding: .utf8) + let decoded3 = String(decoding: encoded3, as: UTF8.self) let expected3 = "{\"dimensions\":{\"stop\":\"drop\"}}" XCTAssertEqual(decoded3, expected3) } diff --git a/Tests/ParseSwiftTests/ParseFileAsyncTests.swift b/Tests/ParseSwiftTests/ParseFileAsyncTests.swift index 3dfe200eb..da920270f 100644 --- a/Tests/ParseSwiftTests/ParseFileAsyncTests.swift +++ b/Tests/ParseSwiftTests/ParseFileAsyncTests.swift @@ -316,9 +316,9 @@ class ParseFileAsyncTests: XCTestCase { // swiftlint:disable:this type_body_leng let downloadTask = URLSession.shared.downloadTask(with: .init(fileURLWithPath: "http://localhost:1337/parse/files/applicationId/d3a37aed0672a024595b766f97133615_logo.svg")) let task = downloadTask as URLSessionTask // swiftlint:disable:next line_length - let uploadCompletion: ((URLSessionTask, Int64, Int64, Int64) -> Void) = { (_: URLSessionTask, _: Int64, _: Int64, _: Int64) -> Void in } + let uploadCompletion: ((URLSessionTask, Int64, Int64, Int64) -> Void) = { (_: URLSessionTask, _: Int64, _: Int64, _: Int64) in } // swiftlint:disable:next line_length - let downloadCompletion: ((URLSessionDownloadTask, Int64, Int64, Int64) -> Void) = { (_: URLSessionDownloadTask, _: Int64, _: Int64, _: Int64) -> Void in } + let downloadCompletion: ((URLSessionDownloadTask, Int64, Int64, Int64) -> Void) = { (_: URLSessionDownloadTask, _: Int64, _: Int64, _: Int64) in } // Add tasks Parse.sessionDelegate.streamDelegates[task] = .init(data: .init()) @@ -358,7 +358,7 @@ class ParseFileAsyncTests: XCTestCase { // swiftlint:disable:this type_body_leng let expectation2 = XCTestExpectation(description: "Call delegate 2") // swiftlint:disable:next line_length - let uploadCompletion: ((URLSessionTask, Int64, Int64, Int64) -> Void) = { (_: URLSessionTask, _: Int64, sent: Int64, total: Int64) -> Void in + let uploadCompletion: ((URLSessionTask, Int64, Int64, Int64) -> Void) = { (_: URLSessionTask, _: Int64, sent: Int64, total: Int64) in if sent < total { Task { let uploadCount = await Parse.sessionDelegate.delegates.uploadDelegates.count @@ -429,7 +429,7 @@ class ParseFileAsyncTests: XCTestCase { // swiftlint:disable:this type_body_leng let expectation2 = XCTestExpectation(description: "Call delegate 2") // swiftlint:disable:next line_length - let downloadCompletion: ((URLSessionDownloadTask, Int64, Int64, Int64) -> Void) = { (_: URLSessionDownloadTask, _: Int64, sent: Int64, total: Int64) -> Void in + let downloadCompletion: ((URLSessionDownloadTask, Int64, Int64, Int64) -> Void) = { (_: URLSessionDownloadTask, _: Int64, sent: Int64, total: Int64) in if sent < total { Task { let downloadCount = await Parse.sessionDelegate.delegates.downloadDelegates.count @@ -497,7 +497,7 @@ class ParseFileAsyncTests: XCTestCase { // swiftlint:disable:this type_body_leng let expectation1 = XCTestExpectation(description: "Call delegate 1") let expectation2 = XCTestExpectation(description: "Call delegate 2") - let streamCompletion: ((InputStream?) -> Void) = { (_: InputStream?) -> Void in + let streamCompletion: ((InputStream?) -> Void) = { (_: InputStream?) in Task { let streamCount = Parse.sessionDelegate.streamDelegates.count let taskCount = await Parse.sessionDelegate.delegates.taskCallbackQueues.count diff --git a/Tests/ParseSwiftTests/ParseHookFunctionRequestTests.swift b/Tests/ParseSwiftTests/ParseHookFunctionRequestTests.swift index fa4e49d94..d0ad8eb5e 100644 --- a/Tests/ParseSwiftTests/ParseHookFunctionRequestTests.swift +++ b/Tests/ParseSwiftTests/ParseHookFunctionRequestTests.swift @@ -82,10 +82,7 @@ class ParseHookFunctionRequestTests: XCTestCase { let failedLoginCount = 3 var accountLockoutExpiresAt = Date() let encodedDate = try ParseCoding.jsonEncoder().encode(accountLockoutExpiresAt) - guard let encodeedDateString = String(data: encodedDate, encoding: .utf8) else { - XCTFail("Should have unwrapped") - return - } + let encodeedDateString = String(decoding: encodedDate, as: UTF8.self) accountLockoutExpiresAt = try ParseCoding.jsonDecoder().decode(Date.self, from: encodedDate) // swiftlint:disable:next line_length let encodedString = "{\"className\":\"_User\",\"sessionToken\":\"\(sessionToken)\",\"_failed_login_count\":\(failedLoginCount),\"_account_lockout_expires_at\":\(encodeedDateString)}" diff --git a/Tests/ParseSwiftTests/ParseLiveQueryTests.swift b/Tests/ParseSwiftTests/ParseLiveQueryTests.swift index 41901390e..d1b6d1e3a 100644 --- a/Tests/ParseSwiftTests/ParseLiveQueryTests.swift +++ b/Tests/ParseSwiftTests/ParseLiveQueryTests.swift @@ -199,7 +199,7 @@ class ParseLiveQueryTests: XCTestCase { let message = await StandardMessage(operation: .connect, additionalProperties: true) let encoded = try ParseCoding.jsonEncoder() .encode(message) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -209,7 +209,7 @@ class ParseLiveQueryTests: XCTestCase { let message = await StandardMessage(operation: .connect) let encoded = try ParseCoding.jsonEncoder() .encode(message) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -223,7 +223,7 @@ class ParseLiveQueryTests: XCTestCase { let message = await StandardMessage(operation: .subscribe, additionalProperties: true) let encoded = try ParseCoding.jsonEncoder() .encode(message) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -232,7 +232,7 @@ class ParseLiveQueryTests: XCTestCase { let message = await StandardMessage(operation: .subscribe, additionalProperties: false) let encoded = try ParseCoding.jsonEncoder() .encode(message) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -248,7 +248,7 @@ class ParseLiveQueryTests: XCTestCase { additionalProperties: true) let encoded = try ParseCoding.jsonEncoder() .encode(message) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -263,7 +263,7 @@ class ParseLiveQueryTests: XCTestCase { additionalProperties: true) let encoded = try ParseCoding.jsonEncoder() .encode(message) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -304,7 +304,7 @@ class ParseLiveQueryTests: XCTestCase { additionalProperties: true) let encoded = try ParseCoding.jsonEncoder() .encode(message) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -337,7 +337,7 @@ class ParseLiveQueryTests: XCTestCase { let message = RedirectResponse(op: .redirect, url: url) let encoded = try ParseCoding.jsonEncoder() .encode(message) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -346,7 +346,7 @@ class ParseLiveQueryTests: XCTestCase { let message = ConnectionResponse(op: .connected, clientId: "yolo", installationId: "naw") let encoded = try ParseCoding.jsonEncoder() .encode(message) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -355,7 +355,7 @@ class ParseLiveQueryTests: XCTestCase { let message = UnsubscribedResponse(op: .connected, requestId: 1, clientId: "yolo", installationId: "naw") let encoded = try ParseCoding.jsonEncoder() .encode(message) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -370,7 +370,7 @@ class ParseLiveQueryTests: XCTestCase { installationId: "naw") let encoded = try ParseCoding.jsonEncoder() .encode(message) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -379,7 +379,7 @@ class ParseLiveQueryTests: XCTestCase { let message = ErrorResponse(op: .error, code: 1, message: "message", reconnect: true) let encoded = try ParseCoding.jsonEncoder() .encode(message) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -391,7 +391,7 @@ class ParseLiveQueryTests: XCTestCase { installationId: "naw") let encoded = try ParseCoding.jsonEncoder() .encode(message) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } diff --git a/Tests/ParseSwiftTests/ParseObjectBatchTests.swift b/Tests/ParseSwiftTests/ParseObjectBatchTests.swift index ec3dc3ff4..7e2abc9b4 100644 --- a/Tests/ParseSwiftTests/ParseObjectBatchTests.swift +++ b/Tests/ParseSwiftTests/ParseObjectBatchTests.swift @@ -87,7 +87,7 @@ class ParseObjectBatchTests: XCTestCase { // swiftlint:disable:this type_body_le let expected = "{\"body\":{\"requests\":[{\"body\":{\"other\":{\"__type\":\"Pointer\",\"className\":\"Game2\",\"objectId\":\"brave\"},\"points\":10},\"method\":\"PUT\",\"path\":\"\\/parse\\/classes\\/GameScore\\/yolo\"}],\"transaction\":false},\"method\":\"POST\",\"path\":\"\\/batch\"}" let encoded = try ParseCoding.parseEncoder().encode(batch, batching: true) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -108,7 +108,7 @@ class ParseObjectBatchTests: XCTestCase { // swiftlint:disable:this type_body_le let expected = "{\"body\":{\"requests\":[{\"body\":{\"other\":{\"__type\":\"Pointer\",\"className\":\"Game2\",\"objectId\":\"brave\"},\"points\":10},\"method\":\"PUT\",\"path\":\"\\/parse\\/classes\\/GameScore\\/yolo\"},{\"body\":{\"other\":{\"__type\":\"Pointer\",\"className\":\"Game2\",\"objectId\":\"brave\"},\"points\":10},\"method\":\"PUT\",\"path\":\"\\/parse\\/classes\\/GameScore\\/yolo\"}],\"transaction\":false},\"method\":\"POST\",\"path\":\"\\/batch\"}" let encoded = try ParseCoding.parseEncoder().encode(batch, batching: true) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -131,7 +131,7 @@ class ParseObjectBatchTests: XCTestCase { // swiftlint:disable:this type_body_le collectChildren: false, objectsSavedBeforeThisOne: nil, filesSavedBeforeThisOne: nil).encoded - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -555,7 +555,7 @@ class ParseObjectBatchTests: XCTestCase { // swiftlint:disable:this type_body_le collectChildren: false, objectsSavedBeforeThisOne: nil, filesSavedBeforeThisOne: nil).encoded - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -1150,7 +1150,7 @@ class ParseObjectBatchTests: XCTestCase { // swiftlint:disable:this type_body_le .encode(score, collectChildren: false, objectsSavedBeforeThisOne: nil, filesSavedBeforeThisOne: nil).encoded - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } diff --git a/Tests/ParseSwiftTests/ParseObjectCustomObjectIdTests.swift b/Tests/ParseSwiftTests/ParseObjectCustomObjectIdTests.swift index 289bf3e90..dfd16ceaf 100644 --- a/Tests/ParseSwiftTests/ParseObjectCustomObjectIdTests.swift +++ b/Tests/ParseSwiftTests/ParseObjectCustomObjectIdTests.swift @@ -169,7 +169,7 @@ class ParseObjectCustomObjectIdTests: XCTestCase { // swiftlint:disable:this typ .encode(body, collectChildren: false, objectsSavedBeforeThisOne: nil, filesSavedBeforeThisOne: nil).encoded - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -197,7 +197,7 @@ class ParseObjectCustomObjectIdTests: XCTestCase { // swiftlint:disable:this typ .encode(body, collectChildren: false, objectsSavedBeforeThisOne: nil, filesSavedBeforeThisOne: nil).encoded - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -222,7 +222,7 @@ class ParseObjectCustomObjectIdTests: XCTestCase { // swiftlint:disable:this typ collectChildren: false, objectsSavedBeforeThisOne: nil, filesSavedBeforeThisOne: nil).encoded - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -249,7 +249,7 @@ class ParseObjectCustomObjectIdTests: XCTestCase { // swiftlint:disable:this typ collectChildren: false, objectsSavedBeforeThisOne: nil, filesSavedBeforeThisOne: nil).encoded - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -274,7 +274,7 @@ class ParseObjectCustomObjectIdTests: XCTestCase { // swiftlint:disable:this typ .encode(body, collectChildren: false, objectsSavedBeforeThisOne: nil, filesSavedBeforeThisOne: nil).encoded - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -300,7 +300,7 @@ class ParseObjectCustomObjectIdTests: XCTestCase { // swiftlint:disable:this typ .encode(body, collectChildren: false, objectsSavedBeforeThisOne: nil, filesSavedBeforeThisOne: nil).encoded - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -325,7 +325,7 @@ class ParseObjectCustomObjectIdTests: XCTestCase { // swiftlint:disable:this typ collectChildren: false, objectsSavedBeforeThisOne: nil, filesSavedBeforeThisOne: nil).encoded - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -352,7 +352,7 @@ class ParseObjectCustomObjectIdTests: XCTestCase { // swiftlint:disable:this typ collectChildren: false, objectsSavedBeforeThisOne: nil, filesSavedBeforeThisOne: nil).encoded - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -377,7 +377,7 @@ class ParseObjectCustomObjectIdTests: XCTestCase { // swiftlint:disable:this typ .encode(body, collectChildren: false, objectsSavedBeforeThisOne: nil, filesSavedBeforeThisOne: nil).encoded - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -403,7 +403,7 @@ class ParseObjectCustomObjectIdTests: XCTestCase { // swiftlint:disable:this typ .encode(body, collectChildren: false, objectsSavedBeforeThisOne: nil, filesSavedBeforeThisOne: nil).encoded - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -428,7 +428,7 @@ class ParseObjectCustomObjectIdTests: XCTestCase { // swiftlint:disable:this typ collectChildren: false, objectsSavedBeforeThisOne: nil, filesSavedBeforeThisOne: nil).encoded - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -455,7 +455,7 @@ class ParseObjectCustomObjectIdTests: XCTestCase { // swiftlint:disable:this typ collectChildren: false, objectsSavedBeforeThisOne: nil, filesSavedBeforeThisOne: nil).encoded - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } diff --git a/Tests/ParseSwiftTests/ParseObjectTests.swift b/Tests/ParseSwiftTests/ParseObjectTests.swift index ea002a26e..7cc648181 100644 --- a/Tests/ParseSwiftTests/ParseObjectTests.swift +++ b/Tests/ParseSwiftTests/ParseObjectTests.swift @@ -890,7 +890,7 @@ class ParseObjectTests: XCTestCase { // swiftlint:disable:this type_body_length .encode(body, collectChildren: false, objectsSavedBeforeThisOne: nil, filesSavedBeforeThisOne: nil).encoded - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -918,7 +918,7 @@ class ParseObjectTests: XCTestCase { // swiftlint:disable:this type_body_length .encode(body, collectChildren: false, objectsSavedBeforeThisOne: nil, filesSavedBeforeThisOne: nil).encoded - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) var empty = score.mergeable @@ -933,7 +933,7 @@ class ParseObjectTests: XCTestCase { // swiftlint:disable:this type_body_length .encode(body2, collectChildren: false, objectsSavedBeforeThisOne: nil, filesSavedBeforeThisOne: nil).encoded - let decoded2 = try XCTUnwrap(String(data: encoded2, encoding: .utf8)) + let decoded2 = String(decoding: encoded2, as: UTF8.self) XCTAssertEqual(decoded2, expected2) } diff --git a/Tests/ParseSwiftTests/ParseOperationTests.swift b/Tests/ParseSwiftTests/ParseOperationTests.swift index 4577bc4de..38c276aa1 100644 --- a/Tests/ParseSwiftTests/ParseOperationTests.swift +++ b/Tests/ParseSwiftTests/ParseOperationTests.swift @@ -112,7 +112,7 @@ class ParseOperationTests: XCTestCase { let expected = "{\"points\":{\"__op\":\"Increment\",\"amount\":1}}" let encoded = try ParseCoding.parseEncoder() .encode(body) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -454,7 +454,7 @@ class ParseOperationTests: XCTestCase { let expected = "{\"points\":{\"__op\":\"Increment\",\"amount\":1}}" let encoded = try ParseCoding.parseEncoder() .encode(operations) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -472,7 +472,7 @@ class ParseOperationTests: XCTestCase { .increment("otherPoints", by: 1.1) let encoded = try ParseCoding.parseEncoder() .encode(operations) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertTrue(decoded.contains("otherPoints\":{\"__op\":\"Increment\",\"amount\":")) XCTAssertTrue(decoded.contains("1.1")) } @@ -484,7 +484,7 @@ class ParseOperationTests: XCTestCase { let expected = "{\"test\":{\"__op\":\"Add\",\"objects\":[\"hello\"]}}" let encoded = try ParseCoding.parseEncoder() .encode(operations) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -495,7 +495,7 @@ class ParseOperationTests: XCTestCase { let expected = "{\"test\":{\"__op\":\"Add\",\"objects\":[\"hello\"]}}" let encoded = try ParseCoding.parseEncoder() .encode(operations) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -506,7 +506,7 @@ class ParseOperationTests: XCTestCase { let expected = "{\"test\":{\"__op\":\"AddUnique\",\"objects\":[\"hello\"]}}" let encoded = try ParseCoding.parseEncoder() .encode(operations) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -517,7 +517,7 @@ class ParseOperationTests: XCTestCase { let expected = "{\"test\":{\"__op\":\"AddUnique\",\"objects\":[\"hello\"]}}" let encoded = try ParseCoding.parseEncoder() .encode(operations) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -531,7 +531,7 @@ class ParseOperationTests: XCTestCase { let expected = "{\"test\":{\"__op\":\"AddRelation\",\"objects\":[{\"__type\":\"Pointer\",\"className\":\"GameScore\",\"objectId\":\"yolo\"}]}}" let encoded = try ParseCoding.parseEncoder() .encode(operations) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -545,7 +545,7 @@ class ParseOperationTests: XCTestCase { let expected = "{\"previous\":{\"__op\":\"AddRelation\",\"objects\":[{\"__type\":\"Pointer\",\"className\":\"Level\",\"objectId\":\"yolo\"}]}}" let encoded = try ParseCoding.parseEncoder() .encode(operations) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -556,7 +556,7 @@ class ParseOperationTests: XCTestCase { let expected = "{\"test\":{\"__op\":\"Remove\",\"objects\":[\"hello\"]}}" let encoded = try ParseCoding.parseEncoder() .encode(operations) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -567,7 +567,7 @@ class ParseOperationTests: XCTestCase { let expected = "{\"test\":{\"__op\":\"Remove\",\"objects\":[\"hello\"]}}" let encoded = try ParseCoding.parseEncoder() .encode(operations) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -581,7 +581,7 @@ class ParseOperationTests: XCTestCase { let expected = "{\"test\":{\"__op\":\"RemoveRelation\",\"objects\":[{\"__type\":\"Pointer\",\"className\":\"GameScore\",\"objectId\":\"yolo\"}]}}" let encoded = try ParseCoding.parseEncoder() .encode(operations) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -595,7 +595,7 @@ class ParseOperationTests: XCTestCase { let expected = "{\"previous\":{\"__op\":\"RemoveRelation\",\"objects\":[{\"__type\":\"Pointer\",\"className\":\"Level\",\"objectId\":\"yolo\"}]}}" let encoded = try ParseCoding.parseEncoder() .encode(operations) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -617,7 +617,7 @@ class ParseOperationTests: XCTestCase { let expected = "{\"test\":{\"__op\":\"Batch\",\"ops\":[{\"__op\":\"Add\",\"objects\":[\"hello\"]},{\"__op\":\"Remove\",\"objects\":[\"world\"]}]}}" let encoded = try ParseCoding.parseEncoder() .encode(operations) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -635,7 +635,7 @@ class ParseOperationTests: XCTestCase { let expected = "{\"test\":{\"__op\":\"Batch\",\"ops\":[{\"__op\":\"AddRelation\",\"objects\":[{\"__type\":\"Pointer\",\"className\":\"GameScore\",\"objectId\":\"yolo\"}]},{\"__op\":\"RemoveRelation\",\"objects\":[{\"__type\":\"Pointer\",\"className\":\"GameScore\",\"objectId\":\"yolo\"}]}]}}" let encoded = try ParseCoding.parseEncoder() .encode(operations) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -646,7 +646,7 @@ class ParseOperationTests: XCTestCase { let expected = "{\"levels\":[\"hello\"],\"points\":15}" let encoded = try ParseCoding.parseEncoder() .encode(operations) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) XCTAssertEqual(operations.target.points, 15) var level = Level(level: 12) @@ -655,7 +655,7 @@ class ParseOperationTests: XCTestCase { let expected2 = "{\"previous\":[{\"level\":12,\"members\":[\"hello\",\"world\"]}]}" let encoded2 = try ParseCoding.parseEncoder() .encode(operations2) - let decoded2 = try XCTUnwrap(String(data: encoded2, encoding: .utf8)) + let decoded2 = String(decoding: encoded2, as: UTF8.self) XCTAssertEqual(decoded2, expected2) XCTAssertEqual(operations2.target.previous, [level]) let operations3 = score.operation.set(("points", \.points), to: nil) @@ -663,7 +663,7 @@ class ParseOperationTests: XCTestCase { let expected3 = "{\"levels\":[\"hello\"],\"points\":null}" let encoded3 = try ParseCoding.parseEncoder() .encode(operations3) - let decoded3 = try XCTUnwrap(String(data: encoded3, encoding: .utf8)) + let decoded3 = String(decoding: encoded3, as: UTF8.self) XCTAssertEqual(decoded3, expected3) XCTAssertNil(operations3.target.points) } @@ -726,7 +726,7 @@ class ParseOperationTests: XCTestCase { let expected = "{}" let encoded = try ParseCoding.parseEncoder() .encode(operations) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) XCTAssertEqual(operations.target.objectId, "test") var level = Level(level: 12) @@ -736,7 +736,7 @@ class ParseOperationTests: XCTestCase { let operations2 = score.operation.set(("previous", \.previous), to: [level]) let encoded2 = try ParseCoding.parseEncoder() .encode(operations2) - let decoded2 = try XCTUnwrap(String(data: encoded2, encoding: .utf8)) + let decoded2 = String(decoding: encoded2, as: UTF8.self) XCTAssertEqual(decoded2, expected2) XCTAssertEqual(operations2.target.previous, [level]) } @@ -747,14 +747,14 @@ class ParseOperationTests: XCTestCase { let expected = "{}" let encoded = try ParseCoding.parseEncoder() .encode(operations) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) let operations2 = score.operation .set(("levels", \.levels), to: nil) let expected2 = "{}" let encoded2 = try ParseCoding.parseEncoder() .encode(operations2) - let decoded2 = try XCTUnwrap(String(data: encoded2, encoding: .utf8)) + let decoded2 = String(decoding: encoded2, as: UTF8.self) XCTAssertEqual(decoded2, expected2) XCTAssertNil(operations2.target.levels) } @@ -765,14 +765,14 @@ class ParseOperationTests: XCTestCase { let expected = "{\"points\":10}" let encoded = try ParseCoding.parseEncoder() .encode(operations) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) let operations2 = score.operation .forceSet(("points", \.points), value: nil) let expected2 = "{\"points\":null}" let encoded2 = try ParseCoding.parseEncoder() .encode(operations2) - let decoded2 = try XCTUnwrap(String(data: encoded2, encoding: .utf8)) + let decoded2 = String(decoding: encoded2, as: UTF8.self) XCTAssertEqual(decoded2, expected2) XCTAssertNil(operations2.target.points) } @@ -784,7 +784,7 @@ class ParseOperationTests: XCTestCase { let expected = "{\"points\":{\"__op\":\"Delete\"}}" let encoded = try ParseCoding.parseEncoder() .encode(operations) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -795,7 +795,7 @@ class ParseOperationTests: XCTestCase { let expected = "{\"points\":{\"__op\":\"Delete\"}}" let encoded = try ParseCoding.parseEncoder() .encode(operations) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } } diff --git a/Tests/ParseSwiftTests/ParsePointerTests.swift b/Tests/ParseSwiftTests/ParsePointerTests.swift index 772d551a1..1eb9302c7 100644 --- a/Tests/ParseSwiftTests/ParsePointerTests.swift +++ b/Tests/ParseSwiftTests/ParsePointerTests.swift @@ -315,7 +315,7 @@ class ParsePointerTests: XCTestCase { objectsSavedBeforeThisOne: nil, filesSavedBeforeThisOne: nil) - let decoded = String(data: encoded.encoded, encoding: .utf8) + let decoded = String(decoding: encoded.encoded, as: UTF8.self) XCTAssertEqual(decoded, // swiftlint:disable:next line_length "{\"other\":{\"__type\":\"Pointer\",\"className\":\"GameScore\",\"objectId\":\"yarr\"},\"points\":50}") @@ -331,7 +331,7 @@ class ParsePointerTests: XCTestCase { let pointerType = try PointerType(score) let encoded = try ParseCoding.parseEncoder().encode(pointerType) - let decoded = String(data: encoded, encoding: .utf8) + let decoded = String(decoding: encoded, as: UTF8.self) XCTAssertEqual(decoded, "{\"__type\":\"Pointer\",\"className\":\"GameScore\",\"objectId\":\"yarr\"}") } diff --git a/Tests/ParseSwiftTests/ParsePushTests.swift b/Tests/ParseSwiftTests/ParsePushTests.swift index be3ba5e4f..741b9efd2 100644 --- a/Tests/ParseSwiftTests/ParsePushTests.swift +++ b/Tests/ParseSwiftTests/ParsePushTests.swift @@ -66,9 +66,7 @@ internal struct ParsePushStatusResponse: ParseObject { func setQueryWhere(_ query: QueryWhere) throws -> Self { var mutatingResponse = self let whereData = try ParseCoding.jsonEncoder().encode(query) - guard let whereString = String(data: whereData, encoding: .utf8) else { - throw ParseError(code: .otherCause, message: "Should have created String") - } + let whereString = String(decoding: whereData, as: UTF8.self) mutatingResponse.query = whereString return mutatingResponse } @@ -76,9 +74,7 @@ internal struct ParsePushStatusResponse: ParseObject { func setPayload(_ payload: V) throws -> Self { var mutatingResponse = self let payloadData = try ParseCoding.jsonEncoder().encode(payload) - guard let payloadString = String(data: payloadData, encoding: .utf8) else { - throw ParseError(code: .otherCause, message: "Should have created String") - } + let payloadString = String(decoding: payloadData, as: UTF8.self) mutatingResponse.payload = payloadString return mutatingResponse } diff --git a/Tests/ParseSwiftTests/ParseQueryTests.swift b/Tests/ParseSwiftTests/ParseQueryTests.swift index f0938583f..320ada440 100644 --- a/Tests/ParseSwiftTests/ParseQueryTests.swift +++ b/Tests/ParseSwiftTests/ParseQueryTests.swift @@ -92,9 +92,7 @@ class ParseQueryTests: XCTestCase { // swiftlint:disable:this type_body_length func encodeDoubleAsString(_ double: Double) throws -> String { let encodedDouble = try ParseCoding.jsonEncoder().encode(double) - guard let decodedDouble = String(data: encodedDouble, encoding: .utf8) else { - throw QueryTestError.couldNotDecodeAsString - } + let decodedDouble = String(decoding: encodedDouble, as: UTF8.self) return decodedDouble } @@ -373,7 +371,7 @@ class ParseQueryTests: XCTestCase { // swiftlint:disable:this type_body_length .select("yolo", "nolo") let encoded = try ParseCoding.jsonEncoder().encode(query) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, // swiftlint:disable:next line_length "{\"_method\":\"GET\",\"excludeKeys\":[\"hello\",\"world\"],\"include\":[\"bar\",\"foo\"],\"keys\":[\"nolo\",\"yolo\"],\"limit\":100,\"skip\":0,\"where\":{}}") @@ -442,7 +440,7 @@ class ParseQueryTests: XCTestCase { // swiftlint:disable:this type_body_length let expected = "{\"body\":{\"_method\":\"GET\",\"limit\":100,\"skip\":0,\"where\":{}},\"method\":\"POST\",\"path\":\"\\/classes\\/GameScore\"}" let encoded = try ParseCoding.jsonEncoder() .encode(command) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -461,7 +459,7 @@ class ParseQueryTests: XCTestCase { // swiftlint:disable:this type_body_length let expected = "{\"body\":{\"_method\":\"GET\",\"explain\":true,\"limit\":100,\"skip\":0,\"where\":{}},\"method\":\"POST\",\"path\":\"\\/classes\\/GameScore\"}" let encoded = try ParseCoding.jsonEncoder() .encode(command) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -785,7 +783,7 @@ class ParseQueryTests: XCTestCase { // swiftlint:disable:this type_body_length let expected = "{\"body\":{\"_method\":\"GET\",\"limit\":1,\"skip\":0,\"where\":{}},\"method\":\"POST\",\"path\":\"\\/classes\\/GameScore\"}" let encoded = try ParseCoding.jsonEncoder() .encode(command) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -797,7 +795,7 @@ class ParseQueryTests: XCTestCase { // swiftlint:disable:this type_body_length let expected = "{\"body\":{\"_method\":\"GET\",\"explain\":true,\"limit\":1,\"skip\":0,\"where\":{}},\"method\":\"POST\",\"path\":\"\\/classes\\/GameScore\"}" let encoded = try ParseCoding.jsonEncoder() .encode(command) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -1037,7 +1035,7 @@ class ParseQueryTests: XCTestCase { // swiftlint:disable:this type_body_length let expected = "{\"body\":{\"_method\":\"GET\",\"count\":true,\"limit\":0,\"skip\":0,\"where\":{}},\"method\":\"POST\",\"path\":\"\\/classes\\/GameScore\"}" let encoded = try ParseCoding.jsonEncoder() .encode(command) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -1049,7 +1047,7 @@ class ParseQueryTests: XCTestCase { // swiftlint:disable:this type_body_length let expected = "{\"body\":{\"_method\":\"GET\",\"count\":true,\"explain\":true,\"limit\":1,\"skip\":0,\"where\":{}},\"method\":\"POST\",\"path\":\"\\/classes\\/GameScore\"}" let encoded = try ParseCoding.jsonEncoder() .encode(command) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -2131,10 +2129,7 @@ class ParseQueryTests: XCTestCase { // swiftlint:disable:this type_body_length do { let encoded = try ParseCoding.jsonEncoder().encode(queryWhere) - guard let decoded = String(data: encoded, encoding: .utf8) else { - XCTFail("Should have casted") - return - } + let decoded = String(decoding: encoded, as: UTF8.self) XCTAssertEqual(expected, decoded) } catch { @@ -2154,10 +2149,7 @@ class ParseQueryTests: XCTestCase { // swiftlint:disable:this type_body_length do { let encoded = try ParseCoding.jsonEncoder().encode(queryWhere) - guard let decoded = String(data: encoded, encoding: .utf8) else { - XCTFail("Should have casted") - return - } + let decoded = String(decoding: encoded, as: UTF8.self) XCTAssertEqual(expected, decoded) } catch { @@ -2177,10 +2169,7 @@ class ParseQueryTests: XCTestCase { // swiftlint:disable:this type_body_length do { let encoded = try ParseCoding.jsonEncoder().encode(queryWhere) - guard let decoded = String(data: encoded, encoding: .utf8) else { - XCTFail("Should have casted") - return - } + let decoded = String(decoding: encoded, as: UTF8.self) XCTAssertEqual(expected, decoded) } catch { @@ -2200,10 +2189,7 @@ class ParseQueryTests: XCTestCase { // swiftlint:disable:this type_body_length do { let encoded = try ParseCoding.jsonEncoder().encode(queryWhere) - guard let decoded = String(data: encoded, encoding: .utf8) else { - XCTFail("Should have casted") - return - } + let decoded = String(decoding: encoded, as: UTF8.self) XCTAssertEqual(expected, decoded) } catch { @@ -3496,7 +3482,7 @@ class ParseQueryTests: XCTestCase { // swiftlint:disable:this type_body_length let expected = "{\"body\":{\"pipeline\":[{\"hello\":\"\(value)\"}]},\"method\":\"POST\",\"path\":\"\\/aggregate\\/GameScore\"}" let encoded = try ParseCoding.jsonEncoder() .encode(aggregate) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -3507,7 +3493,7 @@ class ParseQueryTests: XCTestCase { // swiftlint:disable:this type_body_length let expected = "{\"body\":{\"explain\":true},\"method\":\"POST\",\"path\":\"\\/aggregate\\/GameScore\"}" let encoded = try ParseCoding.jsonEncoder() .encode(command) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -3517,7 +3503,7 @@ class ParseQueryTests: XCTestCase { // swiftlint:disable:this type_body_length let expected = "{\"body\":{\"distinct\":\"hello\"},\"method\":\"POST\",\"path\":\"\\/aggregate\\/GameScore\"}" let encoded = try ParseCoding.jsonEncoder() .encode(aggregate) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -3529,7 +3515,7 @@ class ParseQueryTests: XCTestCase { // swiftlint:disable:this type_body_length let expected = "{\"body\":{\"distinct\":\"hello\",\"explain\":true},\"method\":\"POST\",\"path\":\"\\/aggregate\\/GameScore\"}" let encoded = try ParseCoding.jsonEncoder() .encode(command) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } diff --git a/Tests/ParseSwiftTests/ParseRelationTests.swift b/Tests/ParseSwiftTests/ParseRelationTests.swift index 32995833b..b3809a07e 100644 --- a/Tests/ParseSwiftTests/ParseRelationTests.swift +++ b/Tests/ParseSwiftTests/ParseRelationTests.swift @@ -112,13 +112,13 @@ class ParseRelationTests: XCTestCase { let expected = "{\"__type\":\"Relation\"}" let encoded = try ParseCoding.jsonEncoder().encode(relation) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) relation.className = "hello" let expected2 = "{\"__type\":\"Relation\",\"className\":\"hello\"}" let encoded2 = try ParseCoding.jsonEncoder().encode(relation) - let decoded2 = try XCTUnwrap(String(data: encoded2, encoding: .utf8)) + let decoded2 = String(decoding: encoded2, as: UTF8.self) XCTAssertEqual(decoded2, expected2) XCTAssertEqual(relation.debugDescription, "{\"__type\":\"Relation\",\"className\":\"hello\"}") @@ -141,31 +141,31 @@ class ParseRelationTests: XCTestCase { let expected = "{\"__type\":\"Relation\",\"className\":\"Level\"}" let encoded = try ParseCoding.jsonEncoder().encode(relation) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) relation.className = "hello" let expected2 = "{\"__type\":\"Relation\",\"className\":\"hello\"}" let encoded2 = try ParseCoding.jsonEncoder().encode(relation) - let decoded2 = try XCTUnwrap(String(data: encoded2, encoding: .utf8)) + let decoded2 = String(decoding: encoded2, as: UTF8.self) XCTAssertEqual(decoded2, expected2) var relation2 = try score.relation("yolo", className: "Level") let expected3 = "{\"__type\":\"Relation\",\"className\":\"Level\"}" let encoded3 = try ParseCoding.jsonEncoder().encode(relation2) - let decoded3 = try XCTUnwrap(String(data: encoded3, encoding: .utf8)) + let decoded3 = String(decoding: encoded3, as: UTF8.self) XCTAssertEqual(decoded3, expected3) relation2.className = "hello" let expected4 = "{\"__type\":\"Relation\",\"className\":\"hello\"}" let encoded4 = try ParseCoding.jsonEncoder().encode(relation2) - let decoded4 = try XCTUnwrap(String(data: encoded4, encoding: .utf8)) + let decoded4 = String(decoding: encoded4, as: UTF8.self) XCTAssertEqual(decoded4, expected4) let relation4 = try score.relation("yolo", object: Level.self) let encoded5 = try ParseCoding.jsonEncoder().encode(relation4) - let decoded5 = try XCTUnwrap(String(data: encoded5, encoding: .utf8)) + let decoded5 = String(decoding: encoded5, as: UTF8.self) XCTAssertEqual(decoded5, expected) } @@ -180,13 +180,13 @@ class ParseRelationTests: XCTestCase { let expected = "{\"__type\":\"Relation\",\"className\":\"Level\"}" let encoded = try ParseCoding.jsonEncoder().encode(relation) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) relation.className = "hello" let expected2 = "{\"__type\":\"Relation\",\"className\":\"hello\"}" let encoded2 = try ParseCoding.jsonEncoder().encode(relation) - let decoded2 = try XCTUnwrap(String(data: encoded2, encoding: .utf8)) + let decoded2 = String(decoding: encoded2, as: UTF8.self) XCTAssertEqual(decoded2, expected2) _ = try ParseRelation(parent: score, @@ -197,7 +197,7 @@ class ParseRelationTests: XCTestCase { let expected3 = "{\"__type\":\"Relation\",\"className\":\"Level\"}" let encoded3 = try ParseCoding.jsonEncoder().encode(relation2) - let decoded3 = try XCTUnwrap(String(data: encoded3, encoding: .utf8)) + let decoded3 = String(decoding: encoded3, as: UTF8.self) XCTAssertEqual(decoded3, expected3) } @@ -246,7 +246,7 @@ class ParseRelationTests: XCTestCase { // swiftlint:disable:next line_length let expected = "{\"level\":{\"__op\":\"AddRelation\",\"objects\":[{\"__type\":\"Pointer\",\"className\":\"Level\",\"objectId\":\"nice\"}]}}" let encoded = try ParseCoding.jsonEncoder().encode(operation) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -285,7 +285,7 @@ class ParseRelationTests: XCTestCase { // swiftlint:disable:next line_length let expected = "{\"level\":{\"__op\":\"AddRelation\",\"objects\":[{\"__type\":\"Pointer\",\"className\":\"Level\",\"objectId\":\"nice\"}]}}" let encoded = try ParseCoding.jsonEncoder().encode(operation) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -306,7 +306,7 @@ class ParseRelationTests: XCTestCase { // swiftlint:disable:next line_length let expected = "{\"level\":{\"__op\":\"AddRelation\",\"objects\":[{\"__type\":\"Pointer\",\"className\":\"Level\",\"objectId\":\"nice\"}]}}" let encoded = try ParseCoding.jsonEncoder().encode(operation) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -365,7 +365,7 @@ class ParseRelationTests: XCTestCase { // swiftlint:disable:next line_length let expected = "{\"level\":{\"__op\":\"RemoveRelation\",\"objects\":[{\"__type\":\"Pointer\",\"className\":\"Level\",\"objectId\":\"nice\"}]}}" let encoded = try ParseCoding.jsonEncoder().encode(operation) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -404,7 +404,7 @@ class ParseRelationTests: XCTestCase { // swiftlint:disable:next line_length let expected = "{\"level\":{\"__op\":\"RemoveRelation\",\"objects\":[{\"__type\":\"Pointer\",\"className\":\"Level\",\"objectId\":\"nice\"}]}}" let encoded = try ParseCoding.jsonEncoder().encode(operation) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -425,7 +425,7 @@ class ParseRelationTests: XCTestCase { // swiftlint:disable:next line_length let expected = "{\"level\":{\"__op\":\"RemoveRelation\",\"objects\":[{\"__type\":\"Pointer\",\"className\":\"Level\",\"objectId\":\"nice\"}]}}" let encoded = try ParseCoding.jsonEncoder().encode(operation) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } @@ -471,14 +471,14 @@ class ParseRelationTests: XCTestCase { // swiftlint:disable:next line_length let expected = "{\"_method\":\"GET\",\"limit\":100,\"skip\":0,\"where\":{\"$relatedTo\":{\"key\":\"levels\",\"object\":{\"__type\":\"Pointer\",\"className\":\"GameScore\",\"objectId\":\"hello\"}}}}" let encoded = try ParseCoding.jsonEncoder().encode(query) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) let query2: Query = try relation.query("wow") // swiftlint:disable:next line_length let expected2 = "{\"_method\":\"GET\",\"limit\":100,\"skip\":0,\"where\":{\"$relatedTo\":{\"key\":\"wow\",\"object\":{\"__type\":\"Pointer\",\"className\":\"GameScore\",\"objectId\":\"hello\"}}}}" let encoded2 = try ParseCoding.jsonEncoder().encode(query2) - let decoded2 = try XCTUnwrap(String(data: encoded2, encoding: .utf8)) + let decoded2 = String(decoding: encoded2, as: UTF8.self) XCTAssertEqual(decoded2, expected2) guard let query3 = try level.relation?.query("levels", parent: score) else { @@ -488,7 +488,7 @@ class ParseRelationTests: XCTestCase { // swiftlint:disable:next line_length let expected3 = "{\"_method\":\"GET\",\"limit\":100,\"skip\":0,\"where\":{\"$relatedTo\":{\"key\":\"levels\",\"object\":{\"__type\":\"Pointer\",\"className\":\"GameScore\",\"objectId\":\"hello\"}}}}" let encoded3 = try ParseCoding.jsonEncoder().encode(query3) - let decoded3 = try XCTUnwrap(String(data: encoded3, encoding: .utf8)) + let decoded3 = String(decoding: encoded3, as: UTF8.self) XCTAssertEqual(decoded3, expected3) guard let query4 = try level.relation?.query("levels", parent: score.toPointer()) else { @@ -498,7 +498,7 @@ class ParseRelationTests: XCTestCase { // swiftlint:disable:next line_length let expected4 = "{\"_method\":\"GET\",\"limit\":100,\"skip\":0,\"where\":{\"$relatedTo\":{\"key\":\"levels\",\"object\":{\"__type\":\"Pointer\",\"className\":\"GameScore\",\"objectId\":\"hello\"}}}}" let encoded4 = try ParseCoding.jsonEncoder().encode(query4) - let decoded4 = try XCTUnwrap(String(data: encoded4, encoding: .utf8)) + let decoded4 = String(decoding: encoded4, as: UTF8.self) XCTAssertEqual(decoded4, expected4) } catch { XCTFail("Should not have thrown error") @@ -550,7 +550,7 @@ class ParseRelationTests: XCTestCase { // swiftlint:disable:next line_length let expected = "{\"_method\":\"GET\",\"limit\":100,\"skip\":0,\"where\":{\"$relatedTo\":{\"key\":\"levels\",\"object\":{\"__type\":\"Pointer\",\"className\":\"GameScore\",\"objectId\":\"hello\"}}}}" let encoded = try ParseCoding.jsonEncoder().encode(query) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } catch { XCTFail("Should not have thrown error") @@ -581,7 +581,7 @@ class ParseRelationTests: XCTestCase { // swiftlint:disable:next line_length let expected = "{\"_method\":\"GET\",\"limit\":100,\"skip\":0,\"where\":{\"$relatedTo\":{\"key\":\"levels\",\"object\":{\"__type\":\"Pointer\",\"className\":\"GameScore2\",\"objectId\":\"yolo\"}}}}" let encoded = try ParseCoding.jsonEncoder().encode(query) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } catch { XCTFail("Should not have thrown error") @@ -597,14 +597,14 @@ class ParseRelationTests: XCTestCase { // swiftlint:disable:next line_length let expected = "{\"_method\":\"GET\",\"limit\":100,\"skip\":0,\"where\":{\"$relatedTo\":{\"key\":\"levels\",\"object\":{\"__type\":\"Pointer\",\"className\":\"GameScore\",\"objectId\":\"hello\"}}}}" let encoded = try ParseCoding.jsonEncoder().encode(query) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) let query2 = try Level.queryRelations("levels", parent: score) // swiftlint:disable:next line_length let expected2 = "{\"_method\":\"GET\",\"limit\":100,\"skip\":0,\"where\":{\"$relatedTo\":{\"key\":\"levels\",\"object\":{\"__type\":\"Pointer\",\"className\":\"GameScore\",\"objectId\":\"hello\"}}}}" let encoded2 = try ParseCoding.jsonEncoder().encode(query2) - let decoded2 = try XCTUnwrap(String(data: encoded2, encoding: .utf8)) + let decoded2 = String(decoding: encoded2, as: UTF8.self) XCTAssertEqual(decoded2, expected2) } } diff --git a/Tests/ParseSwiftTests/ParseRoleTests.swift b/Tests/ParseSwiftTests/ParseRoleTests.swift index 43c17336f..55f2c2392 100644 --- a/Tests/ParseSwiftTests/ParseRoleTests.swift +++ b/Tests/ParseSwiftTests/ParseRoleTests.swift @@ -199,7 +199,7 @@ class ParseRoleTests: XCTestCase { .encode(body, collectChildren: false, objectsSavedBeforeThisOne: nil, filesSavedBeforeThisOne: nil).encoded - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) var empty = role.mergeable @@ -266,7 +266,7 @@ class ParseRoleTests: XCTestCase { } let expected = "{\"__type\":\"Relation\",\"className\":\"_User\"}" let encoded = try ParseCoding.jsonEncoder().encode(userRoles) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) XCTAssertEqual(userRoles.key, "users") @@ -295,7 +295,7 @@ class ParseRoleTests: XCTestCase { userRoles.key = nil let expected = "{\"__type\":\"Relation\",\"className\":\"_User\"}" let encoded = try ParseCoding.jsonEncoder().encode(userRoles) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) XCTAssertNil(userRoles.key) @@ -357,7 +357,7 @@ class ParseRoleTests: XCTestCase { } let expected = "{\"__type\":\"Relation\",\"className\":\"_User\"}" let encoded = try ParseCoding.jsonEncoder().encode(userRoles) - let decoded = String(data: encoded, encoding: .utf8) + let decoded = String(decoding: encoded, as: UTF8.self) XCTAssertEqual(decoded, expected) XCTAssertEqual(userRoles.key, "users") @@ -368,7 +368,7 @@ class ParseRoleTests: XCTestCase { // swiftlint:disable:next line_length let expected2 = "{\"users\":{\"__op\":\"RemoveRelation\",\"objects\":[{\"__type\":\"Pointer\",\"className\":\"_User\",\"objectId\":\"heel\"}]}}" let encoded2 = try ParseCoding.jsonEncoder().encode(operation) - let decoded2 = try XCTUnwrap(try XCTUnwrap(String(data: encoded2, encoding: .utf8))) + let decoded2 = String(decoding: encoded2, as: UTF8.self) XCTAssertEqual(decoded2, expected2) } @@ -386,7 +386,7 @@ class ParseRoleTests: XCTestCase { userRoles.key = nil let expected = "{\"__type\":\"Relation\",\"className\":\"_User\"}" let encoded = try ParseCoding.jsonEncoder().encode(userRoles) - let decoded = String(data: encoded, encoding: .utf8) + let decoded = String(decoding: encoded, as: UTF8.self) XCTAssertEqual(decoded, expected) XCTAssertNil(userRoles.key) @@ -397,7 +397,7 @@ class ParseRoleTests: XCTestCase { // swiftlint:disable:next line_length let expected2 = "{\"users\":{\"__op\":\"RemoveRelation\",\"objects\":[{\"__type\":\"Pointer\",\"className\":\"_User\",\"objectId\":\"heel\"}]}}" let encoded2 = try ParseCoding.jsonEncoder().encode(operation) - let decoded2 = try XCTUnwrap(try XCTUnwrap(String(data: encoded2, encoding: .utf8))) + let decoded2 = String(decoding: encoded2, as: UTF8.self) XCTAssertEqual(decoded2, expected2) } @@ -449,7 +449,7 @@ class ParseRoleTests: XCTestCase { } let expected = "{\"__type\":\"Relation\",\"className\":\"_Role\"}" let encoded = try ParseCoding.jsonEncoder().encode(roles) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) XCTAssertEqual(roles.key, "roles") @@ -838,7 +838,7 @@ class ParseRoleTests: XCTestCase { roles.key = nil let expected = "{\"__type\":\"Relation\",\"className\":\"_Role\"}" let encoded = try ParseCoding.jsonEncoder().encode(roles) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) XCTAssertNil(roles.key) @@ -900,7 +900,7 @@ class ParseRoleTests: XCTestCase { } let expected = "{\"__type\":\"Relation\",\"className\":\"_Role\"}" let encoded = try ParseCoding.jsonEncoder().encode(roles) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) XCTAssertEqual(roles.key, "roles") @@ -929,7 +929,7 @@ class ParseRoleTests: XCTestCase { roles.key = nil let expected = "{\"__type\":\"Relation\",\"className\":\"_Role\"}" let encoded = try ParseCoding.jsonEncoder().encode(roles) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) XCTAssertNil(roles.key) @@ -960,7 +960,7 @@ class ParseRoleTests: XCTestCase { // swiftlint:disable:next line_length let expected = "{\"_method\":\"GET\",\"limit\":100,\"skip\":0,\"where\":{\"$relatedTo\":{\"key\":\"users\",\"object\":{\"__type\":\"Pointer\",\"className\":\"_Role\",\"objectId\":\"yolo\"}}}}" let encoded = try ParseCoding.jsonEncoder().encode(query) - let decoded = try XCTUnwrap(String(data: encoded, encoding: .utf8)) + let decoded = try XCTUnwrap(String(decoding: encoded, as: UTF8.self)) XCTAssertEqual(decoded, expected) } diff --git a/Tests/ParseSwiftTests/ParseSessionTests.swift b/Tests/ParseSwiftTests/ParseSessionTests.swift index b92478619..733cf41b5 100644 --- a/Tests/ParseSwiftTests/ParseSessionTests.swift +++ b/Tests/ParseSwiftTests/ParseSessionTests.swift @@ -119,7 +119,7 @@ class ParseSessionTests: XCTestCase { func testParseURLSessionDefaultCertificatePinning() throws { let expectation1 = XCTestExpectation(description: "Authentication") URLSession.parse.delegate?.urlSession?(URLSession.parse, - didReceive: .init()) { (challenge, credential) -> Void in + didReceive: .init()) { (challenge, credential) in XCTAssertEqual(challenge, .performDefaultHandling) XCTAssertNil(credential) expectation1.fulfill() @@ -159,7 +159,7 @@ class ParseSessionTests: XCTestCase { }) let expectation1 = XCTestExpectation(description: "Authentication") URLSession.parse.delegate?.urlSession?(URLSession.parse, - didReceive: .init()) { (challenge, credential) -> Void in + didReceive: .init()) { (challenge, credential) in XCTAssertEqual(challenge, .cancelAuthenticationChallenge) XCTAssertEqual(credential, .none) expectation1.fulfill()