add decode array method

This commit is contained in:
panxi 2019-12-12 17:28:02 -05:00
parent 46c092f99c
commit eb4e8fd816

View File

@ -102,6 +102,13 @@ extension KeyedDecodingContainer where Key: CodingKey {
}
return models.count > 0 ? models : nil
}
public func decodeArray<C:CodingKey>(codingKey: KeyedDecodingContainer<K>.Key, typeCodingKey: C) throws -> [Model] {
guard let models: [Model] = try decodeArrayIfPresent(codingKey: codingKey, typeCodingKey: typeCodingKey) else {
throw ModelRegistry.Error.decoderErrorObjectNotPresent
}
return models
}
}