fix array decode if it's nil

This commit is contained in:
panxi 2019-12-02 12:04:32 -05:00
parent 347fd9557d
commit 72758675dc

View File

@ -65,13 +65,17 @@ extension KeyedDecodingContainer where Key: CodingKey {
public func decodeArrayIfPresent<C:CodingKey>(codingKey: KeyedDecodingContainer<K>.Key, typeCodingKey: C) throws -> [Model]? {
var unkeyedContainer = try nestedUnkeyedContainer(forKey: codingKey)
var unkeyedContainer: UnkeyedDecodingContainer?
do {
unkeyedContainer = try nestedUnkeyedContainer(forKey: codingKey)
} catch {
return nil
}
var otherUnkeyedContainer = try nestedUnkeyedContainer(forKey: codingKey)
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 {
return nil
}