Skip to content

Commit 309cfec

Browse files
committed
Fix JSON parsing error by making formattedPrice & price optional for SearchResult.
Use new `displayPrice` to get around optional `formattedPrice`. Doesn't handle i18n, but we can clean that up after we completely redo JSON handling. Resolve #493 Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com>
1 parent ca921c0 commit 309cfec

3 files changed

Lines changed: 8 additions & 4 deletions

File tree

Sources/mas/Formatters/AppInfoFormatter.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ enum AppInfoFormatter {
1818
let headline = [
1919
"\(app.trackName)",
2020
"\(app.version)",
21-
"[\(app.formattedPrice)]",
21+
"[\(app.displayPrice)]",
2222
]
2323
.joined(separator: " ")
2424

Sources/mas/Formatters/SearchResultFormatter.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ enum SearchResultFormatter {
2929
let version = result.version
3030

3131
if includePrice {
32-
output += String(format: "%12lu %@ (%@) %@\n", appID, appName, version, result.formattedPrice)
32+
output += String(format: "%12lu %@ (%@) %@\n", appID, appName, version, result.displayPrice)
3333
} else {
3434
output += String(format: "%12lu %@ (%@)\n", appID, appName, version)
3535
}

Sources/mas/Models/SearchResult.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,20 @@ struct SearchResult: Decodable {
1010
var bundleId: String
1111
var currentVersionReleaseDate: String
1212
var fileSizeBytes: String
13-
var formattedPrice: String
13+
var formattedPrice: String?
1414
var minimumOsVersion: String
15-
var price: Double
15+
var price: Double?
1616
var sellerName: String
1717
var sellerUrl: String?
1818
var trackId: AppID
1919
var trackName: String
2020
var trackViewUrl: String
2121
var version: String
2222

23+
var displayPrice: String {
24+
formattedPrice ?? "Unknown"
25+
}
26+
2327
init(
2428
bundleId: String = "",
2529
currentVersionReleaseDate: String = "",

0 commit comments

Comments
 (0)