Skip to content

Commit ee37417

Browse files
authored
Add Decodable impl for Axis (#1001)
1 parent 5e62bde commit ee37417

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

Sources/LiveViewNative/Utils/Axis.swift

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ extension Axis.Set: Decodable, AttributeDecodable {
2121
if let alignment = Self(string: string) {
2222
self = alignment
2323
} else {
24-
throw DecodingError.dataCorrupted(.init(codingPath: container.codingPath, debugDescription: "expected valid value for HorizontalAlignment"))
24+
throw DecodingError.dataCorrupted(.init(codingPath: container.codingPath, debugDescription: "expected valid value for Axis.Set"))
2525
}
2626
}
2727

@@ -44,3 +44,22 @@ extension Axis.Set: Decodable, AttributeDecodable {
4444
self = result
4545
}
4646
}
47+
48+
/// A horizontal or vertical dimension.
49+
///
50+
/// Possible values:
51+
/// * `horizontal`
52+
/// * `vertical`
53+
extension Axis: Decodable {
54+
public init(from decoder: Decoder) throws {
55+
let container = try decoder.singleValueContainer()
56+
switch try container.decode(String.self) {
57+
case "horizontal":
58+
self = .horizontal
59+
case "vertical":
60+
self = .vertical
61+
default:
62+
throw DecodingError.dataCorrupted(.init(codingPath: container.codingPath, debugDescription: "expected valid value for Axis"))
63+
}
64+
}
65+
}

0 commit comments

Comments
 (0)