fix array decode if it's nil
This commit is contained in:
parent
347fd9557d
commit
72758675dc
@ -65,13 +65,17 @@ extension KeyedDecodingContainer where Key: CodingKey {
|
|||||||
|
|
||||||
|
|
||||||
public func decodeArrayIfPresent<C:CodingKey>(codingKey: KeyedDecodingContainer<K>.Key, typeCodingKey: C) throws -> [Model]? {
|
public func decodeArrayIfPresent<C:CodingKey>(codingKey: KeyedDecodingContainer<K>.Key, typeCodingKey: C) throws -> [Model]? {
|
||||||
|
var unkeyedContainer: UnkeyedDecodingContainer?
|
||||||
var unkeyedContainer = try nestedUnkeyedContainer(forKey: codingKey)
|
do {
|
||||||
|
unkeyedContainer = try nestedUnkeyedContainer(forKey: codingKey)
|
||||||
|
} catch {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
var otherUnkeyedContainer = try nestedUnkeyedContainer(forKey: codingKey)
|
var otherUnkeyedContainer = try nestedUnkeyedContainer(forKey: codingKey)
|
||||||
var attributes = [Model.Type]()
|
var attributes = [Model.Type]()
|
||||||
while !unkeyedContainer.isAtEnd {
|
while !unkeyedContainer!.isAtEnd {
|
||||||
|
|
||||||
let meta = try unkeyedContainer.nestedContainer(keyedBy: C.self)
|
let meta = try unkeyedContainer!.nestedContainer(keyedBy: C.self)
|
||||||
guard let type = try meta.decodeIfPresent(String.self, forKey: typeCodingKey) else {
|
guard let type = try meta.decodeIfPresent(String.self, forKey: typeCodingKey) else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user