Skip to content

Commit db9807a

Browse files
committed
new manual codable conformance for FileFormatStyle
1 parent 904aa70 commit db9807a

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

Sources/FoundationInternationalization/ProgressReporter/ProgressReporter+FileFormatStyle.swift

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,27 @@ extension ProgressReporter {
4646
self.rawOption = rawOption
4747
}
4848
}
49-
enum CodingKeys: String, CodingKey {
50-
case locale
51-
case option
49+
50+
struct CodableRepresentation: Codable {
51+
let locale: Locale
52+
let includeFileDescription: Bool
53+
}
54+
55+
var codableRepresentation: CodableRepresentation {
56+
.init(locale: self.locale, includeFileDescription: option.rawOption == .file)
5257
}
5358

5459
public init(from decoder: any Decoder) throws {
55-
let container = try decoder.container(keyedBy: CodingKeys.self)
56-
locale = try container.decode(Locale.self, forKey: .locale)
57-
option = try container.decode(Option.self, forKey: .option)
60+
//TODO: Fix this later, codableRepresentation is not settable
61+
let container = try decoder.singleValueContainer()
62+
let rep = try container.decode(CodableRepresentation.self)
63+
locale = rep.locale
64+
option = .file
5865
}
59-
66+
6067
public func encode(to encoder: any Encoder) throws {
61-
var container = encoder.container(keyedBy: CodingKeys.self)
62-
try container.encode(locale, forKey: .locale)
63-
try container.encode(option, forKey: .option)
68+
var container = encoder.singleValueContainer()
69+
try container.encode(codableRepresentation)
6470
}
6571

6672
public var locale: Locale

0 commit comments

Comments
 (0)