diff --git a/ElementX/Sources/Other/Extensions/Dictionary.swift b/ElementX/Sources/Other/Extensions/Dictionary.swift index b26a585c50..4793c64636 100644 --- a/ElementX/Sources/Other/Extensions/Dictionary.swift +++ b/ElementX/Sources/Other/Extensions/Dictionary.swift @@ -22,7 +22,7 @@ extension Dictionary { options: [.fragmentsAllowed, .sortedKeys]) else { return nil } - return String(decoding: data, as: UTF8.self) + return String(data: data, encoding: .utf8) } /// Returns a dictionary containing the original values keyed by the results of mapping the given closure over its keys. diff --git a/ElementX/Sources/Services/BugReport/BugReportService.swift b/ElementX/Sources/Services/BugReport/BugReportService.swift index 252b084581..09cae3a9b7 100644 --- a/ElementX/Sources/Services/BugReport/BugReportService.swift +++ b/ElementX/Sources/Services/BugReport/BugReportService.swift @@ -175,14 +175,14 @@ class BugReportService: NSObject, BugReportServiceProtocol { let (data, response) = try await session.dataWithRetry(for: request, delegate: self) guard let httpResponse = response as? HTTPURLResponse else { - let errorDescription = String(decoding: data, as: UTF8.self).trimmingCharacters(in: .whitespacesAndNewlines) + let errorDescription = String(data: data, encoding: .utf8)?.trimmingCharacters(in: .whitespacesAndNewlines) ?? "Unknown" MXLog.error("Failed to submit bug report: \(errorDescription)") MXLog.error("Response: \(response)") return .failure(.serverError(response, errorDescription)) } guard httpResponse.statusCode == 200 else { - let errorDescription = String(decoding: data, as: UTF8.self).trimmingCharacters(in: .whitespacesAndNewlines) + let errorDescription = String(data: data, encoding: .utf8)?.trimmingCharacters(in: .whitespacesAndNewlines) ?? "Unknown" MXLog.error("Failed to submit bug report: \(errorDescription) (\(httpResponse.statusCode))") MXLog.error("Response: \(httpResponse)") return .failure(.httpError(httpResponse, errorDescription)) diff --git a/ElementX/Sources/Services/Timeline/TimelineItemProxy.swift b/ElementX/Sources/Services/Timeline/TimelineItemProxy.swift index 1b3d06711c..371030fdf4 100644 --- a/ElementX/Sources/Services/Timeline/TimelineItemProxy.swift +++ b/ElementX/Sources/Services/Timeline/TimelineItemProxy.swift @@ -162,7 +162,7 @@ struct TimelineItemDebugInfo: Identifiable, CustomStringConvertible { return nil } - return String(decoding: jsonData, as: UTF8.self) + return String(data: jsonData, encoding: .utf8) } } diff --git a/ElementX/Sources/UITests/UITestsSignalling.swift b/ElementX/Sources/UITests/UITestsSignalling.swift index 7775c8767a..ebe2e0dc7e 100644 --- a/ElementX/Sources/UITests/UITestsSignalling.swift +++ b/ElementX/Sources/UITests/UITestsSignalling.swift @@ -146,8 +146,11 @@ enum UITestsSignalling { let encoder = JSONEncoder() encoder.outputFormatting = .sortedKeys - guard let data = try? encoder.encode(self) else { return "unknown" } - return String(decoding: data, as: UTF8.self) + guard let data = try? encoder.encode(self), + let string = String(data: data, encoding: .utf8) else { + return "unknown" + } + return string } init?(rawValue: String) { @@ -172,7 +175,7 @@ enum UITestsSignalling { /// Processes string data from the file and publishes its signal. private func processFileData(_ data: Data) { - let rawMessage = String(decoding: data, as: UTF8.self) + guard let rawMessage = String(data: data, encoding: .utf8) else { return } guard let message = Message(rawValue: rawMessage), message.mode != mode // Filter out messages sent by this client.