File tree 2 files changed +30
-3
lines changed
Sources/FeaturevisorTypes
2 files changed +30
-3
lines changed Original file line number Diff line number Diff line change
1
+ import Foundation
2
+
3
+ extension KeyedDecodingContainer {
4
+
5
+ private struct EmptyStructData : Codable { }
6
+
7
+ func decodeArrayElements< T: Decodable > (
8
+ forKey key: KeyedDecodingContainer < K > . Key
9
+ ) throws -> [ T ] where T: Decodable {
10
+
11
+ var arrayElements : [ T ] = [ ]
12
+
13
+ let container = try nestedUnkeyedContainer ( forKey: key)
14
+ var containerCopy = container
15
+ while !containerCopy. isAtEnd {
16
+ if let element = try ? containerCopy. decode ( T . self) {
17
+ arrayElements. append ( element)
18
+ }
19
+ else {
20
+ // @TODO: add error handling for object decoding failed
21
+ _ = try containerCopy. decode ( EmptyStructData . self)
22
+ }
23
+ }
24
+
25
+ return arrayElements
26
+ }
27
+ }
Original file line number Diff line number Diff line change @@ -793,9 +793,9 @@ public struct DatafileContent: Decodable {
793
793
794
794
schemaVersion = try values. decode ( String . self, forKey: . schemaVersion)
795
795
revision = try values. decode ( String . self, forKey: . revision)
796
- attributes = try values. decode ( [ Attribute ] . self , forKey: . attributes)
797
- segments = try values. decode ( [ Segment ] . self , forKey: . segments)
798
- features = try values. decode ( [ Feature ] . self , forKey: . features)
796
+ attributes = try values. decodeArrayElements ( forKey: . attributes)
797
+ segments = try values. decodeArrayElements ( forKey: . segments)
798
+ features = try values. decodeArrayElements ( forKey: . features)
799
799
}
800
800
801
801
enum CodingKeys : String , CodingKey {
You can’t perform that action at this time.
0 commit comments