add decode array method

This commit is contained in:
panxi 2019-12-12 17:28:02 -05:00
parent b4994b0351
commit ce1559dc15

View File

@ -20,4 +20,15 @@ extension KeyedDecodingContainer where Key : CodingKey {
public func decodeIfPresent(codingKey: KeyedDecodingContainer<K>.Key) throws -> MoleculeProtocol? {
return try decodeIfPresent(codingKey: codingKey, typeCodingKey: TypeCodingKey.moleculeName)
}
public func decodeArray(codingKey: KeyedDecodingContainer<K>.Key) throws -> [MoleculeProtocol] {
guard let models = try decodeArray(codingKey: codingKey, typeCodingKey: TypeCodingKey.moleculeName) as? [MoleculeProtocol] else {
throw ModelRegistry.Error.decoderError
}
return models
}
public func decodeArrayIfPresent(codingKey: KeyedDecodingContainer<K>.Key) throws -> [MoleculeProtocol]? {
return try decodeArrayIfPresent(codingKey: codingKey, typeCodingKey: TypeCodingKey.moleculeName) as? [MoleculeProtocol]
}
}