@@ -61,7 +61,37 @@ public enum AttributeValue: Equatable, CustomStringConvertible, Hashable {
6161 }
6262}
6363
64- internal struct AttributeValueExplicitCodable : Codable {
64+ public extension AttributeValue {
65+ init ( _ value: String ) {
66+ self = . string( value)
67+ }
68+
69+ init ( _ value: Bool ) {
70+ self = . bool( value)
71+ }
72+
73+ init ( _ value: Int ) {
74+ self = . int( value)
75+ }
76+
77+ init ( _ value: Double ) {
78+ self = . double( value)
79+ }
80+
81+ init ( _ value: [ String ] ) {
82+ self = . stringArray( value)
83+ }
84+
85+ init ( _ value: [ Int ] ) {
86+ self = . intArray( value)
87+ }
88+
89+ init ( _ value: [ Double ] ) {
90+ self = . doubleArray( value)
91+ }
92+ }
93+
94+ internal struct AttributeValueExplicitCodable : Codable {
6595 let attributeValue : AttributeValue
6696
6797 enum CodingKeys : String , CodingKey {
@@ -122,32 +152,31 @@ internal struct AttributeValueExplicitCodable : Codable {
122152 }
123153
124154 public func encode( to encoder: Encoder ) throws {
125-
126155 var container = encoder. container ( keyedBy: CodingKeys . self)
127156
128157 switch self . attributeValue {
129- case . string( let value) :
158+ case let . string( value) :
130159 var nestedContainer = container. nestedContainer ( keyedBy: AssociatedValueCodingKeys . self, forKey: . string)
131160 try nestedContainer. encode ( value, forKey: . associatedValue)
132- case . bool( let value) :
161+ case let . bool( value) :
133162 var nestedContainer = container. nestedContainer ( keyedBy: AssociatedValueCodingKeys . self, forKey: . bool)
134163 try nestedContainer. encode ( value, forKey: . associatedValue)
135- case . int( let value) :
164+ case let . int( value) :
136165 var nestedContainer = container. nestedContainer ( keyedBy: AssociatedValueCodingKeys . self, forKey: . int)
137166 try nestedContainer. encode ( value, forKey: . associatedValue)
138- case . double( let value) :
167+ case let . double( value) :
139168 var nestedContainer = container. nestedContainer ( keyedBy: AssociatedValueCodingKeys . self, forKey: . double)
140169 try nestedContainer. encode ( value, forKey: . associatedValue)
141- case . stringArray( let value) :
170+ case let . stringArray( value) :
142171 var nestedContainer = container. nestedContainer ( keyedBy: AssociatedValueCodingKeys . self, forKey: . stringArray)
143172 try nestedContainer. encode ( value, forKey: . associatedValue)
144- case . boolArray( let value) :
173+ case let . boolArray( value) :
145174 var nestedContainer = container. nestedContainer ( keyedBy: AssociatedValueCodingKeys . self, forKey: . boolArray)
146175 try nestedContainer. encode ( value, forKey: . associatedValue)
147- case . intArray( let value) :
176+ case let . intArray( value) :
148177 var nestedContainer = container. nestedContainer ( keyedBy: AssociatedValueCodingKeys . self, forKey: . intArray)
149178 try nestedContainer. encode ( value, forKey: . associatedValue)
150- case . doubleArray( let value) :
179+ case let . doubleArray( value) :
151180 var nestedContainer = container. nestedContainer ( keyedBy: AssociatedValueCodingKeys . self, forKey: . doubleArray)
152181 try nestedContainer. encode ( value, forKey: . associatedValue)
153182 }
@@ -157,11 +186,10 @@ internal struct AttributeValueExplicitCodable : Codable {
157186#if swift(>=5.5)
158187// swift 5.5 supports synthesizing Codable for enums with associated values
159188// see https://github.com/apple/swift-evolution/blob/main/proposals/0295-codable-synthesis-for-enums-with-associated-values.md
160- extension AttributeValue : Codable { }
189+ extension AttributeValue : Codable { }
161190#else
162191// for older swift versions use a forward compatible explicit Codable implementation
163192extension AttributeValue : Codable {
164-
165193 public init ( from decoder: Decoder ) throws {
166194 let explicitDecoded = try AttributeValueExplicitCodable ( from: decoder)
167195
0 commit comments