Skip to content

Commit

Permalink
Merge pull request #505 from Esri/Ting/FixStringLinterWarnings
Browse files Browse the repository at this point in the history
[Update] Fix linter warnings for string <-> data conversion
  • Loading branch information
yo1995 authored Aug 30, 2024
2 parents 1e5007b + 28f55ac commit 80eee62
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Scripts/DowloadPortalItemData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func name(ofFileInArchiveAt url: URL) throws -> String {
process.waitUntilExit()

let filenameData = outputPipe.fileHandleForReading.readDataToEndOfFile()
return String(data: filenameData, encoding: .utf8)!.trimmingCharacters(in: .whitespacesAndNewlines)
return String(decoding: filenameData, as: UTF8.self).trimmingCharacters(in: .whitespacesAndNewlines)
}

/// Counts files in a ZIP archive.
Expand All @@ -108,7 +108,7 @@ func count(ofFilesInArchiveAt url: URL) throws -> Int {
// To extract the count, cut the string at the first whitespace.
let totalsInfo = outputPipe.fileHandleForReading.readDataToEndOfFile()
// `UInt8(32)` is space in ASCII.
let totalsCount = String(data: totalsInfo.prefix(while: { $0 != 32 }), encoding: .utf8)!
let totalsCount = String(decoding: totalsInfo.prefix(while: { $0 != 32 }), as: UTF8.self)
return Int(totalsCount)!
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ extension NavigateRouteWithReroutingView {

// Set up the data source's locations using a local JSON file.
let jsonData = try Data(contentsOf: .sanDiegoTourPath)
guard let jsonString = String(data: jsonData, encoding: .utf8) else { return }
let jsonString = String(decoding: jsonData, as: UTF8.self)
let routePolyline = try Polyline.fromJSON(jsonString)
simulatedDataSource.setSimulatedLocations(with: routePolyline)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ extension Array: RawRepresentable where Element == String {

/// The raw value of the array.
public var rawValue: String {
guard let data = try? JSONEncoder().encode(self),
let result = String(data: data, encoding: .utf8)
else { return "[]" }
return result
guard let data = try? JSONEncoder().encode(self) else { return "[]" }
return String(decoding: data, as: UTF8.self)
}
}

0 comments on commit 80eee62

Please sign in to comment.