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>
This commit is contained in:
Ross Goldberg 2024-11-20 00:39:52 -05:00
parent ca921c07d8
commit 309cfec38d
No known key found for this signature in database
3 changed files with 8 additions and 4 deletions

View file

@ -18,7 +18,7 @@ enum AppInfoFormatter {
let headline = [
"\(app.trackName)",
"\(app.version)",
"[\(app.formattedPrice)]",
"[\(app.displayPrice)]",
]
.joined(separator: " ")

View file

@ -29,7 +29,7 @@ enum SearchResultFormatter {
let version = result.version
if includePrice {
output += String(format: "%12lu %@ (%@) %@\n", appID, appName, version, result.formattedPrice)
output += String(format: "%12lu %@ (%@) %@\n", appID, appName, version, result.displayPrice)
} else {
output += String(format: "%12lu %@ (%@)\n", appID, appName, version)
}

View file

@ -10,9 +10,9 @@ struct SearchResult: Decodable {
var bundleId: String
var currentVersionReleaseDate: String
var fileSizeBytes: String
var formattedPrice: String
var formattedPrice: String?
var minimumOsVersion: String
var price: Double
var price: Double?
var sellerName: String
var sellerUrl: String?
var trackId: AppID
@ -20,6 +20,10 @@ struct SearchResult: Decodable {
var trackViewUrl: String
var version: String
var displayPrice: String {
formattedPrice ?? "Unknown"
}
init(
bundleId: String = "",
currentVersionReleaseDate: String = "",