Skip to content

Commit a3c6024

Browse files
committed
possible fix for #51
1 parent 5bce789 commit a3c6024

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

Source/JSONJoy.swift

+17-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,23 @@ open class JSONDecoder {
103103
return value as? [JSONDecoder]
104104
}
105105

106-
106+
/**
107+
get typed `Array` of `JSONJoy` as an optional
108+
*/
109+
public func getOptional<T: JSONJoy>() -> [T]? {
110+
guard let a = getOptionalArray() else { return nil }
111+
do { return try a.reduce([T]()) { $0.0 + [try T($0.1)] } }
112+
catch { return nil }
113+
}
114+
115+
/**
116+
get typed `Array` of `JSONJoy` as an optional
117+
*/
118+
public func getOptional<T: JSONBasicType>() -> [T]? {
119+
guard let a = getOptionalArray() else { return nil }
120+
do { return try a.reduce([T]()) { $0.0 + [try $0.1.get()] } }
121+
catch { return nil }
122+
}
107123

108124
/**
109125
Array access support

0 commit comments

Comments
 (0)