diff --git a/Sources/XcodeDeadStrings/DeadStringData.swift b/Sources/XcodeDeadStrings/DeadStringData.swift index 73f9510..342a7bd 100644 --- a/Sources/XcodeDeadStrings/DeadStringData.swift +++ b/Sources/XcodeDeadStrings/DeadStringData.swift @@ -61,7 +61,9 @@ public struct DeadStringsData { for (url, rangesToDelete) in stringsToDelete { let data = FileManager.default.contents(atPath: url.path) ?? Data() - var contents = String(decoding: data, as: UTF8.self) + var contents = String(data: data, encoding: .utf8) + ?? String(data: data, encoding: .utf16) + ?? "" for range in rangesToDelete { contents.removeSubrange(range) } diff --git a/Sources/XcodeDeadStrings/ExtractLocalizedKeys.swift b/Sources/XcodeDeadStrings/ExtractLocalizedKeys.swift index 293aacb..6926de9 100644 --- a/Sources/XcodeDeadStrings/ExtractLocalizedKeys.swift +++ b/Sources/XcodeDeadStrings/ExtractLocalizedKeys.swift @@ -78,7 +78,9 @@ func extractLocalizedKeys(from contents: String, url: URL) -> [LocationStringRes func extractLocalizedKeys(fromFileAt url: URL) -> [LocationStringResult] { guard let data = FileManager.default.contents(atPath: url.path) else { return [] } - let contents = String(decoding: data, as: UTF8.self) + let contents = String(data: data, encoding: .utf8) + ?? String(data: data, encoding: .utf16) + ?? "" return extractLocalizedKeys(from: contents, url: url) }