diff --git a/MVMCoreUI/Models/Extensions/ModelHelper.swift b/MVMCoreUI/Models/Extensions/ModelHelper.swift index da5e0d56..b4d0b1e2 100644 --- a/MVMCoreUI/Models/Extensions/ModelHelper.swift +++ b/MVMCoreUI/Models/Extensions/ModelHelper.swift @@ -20,4 +20,15 @@ extension KeyedDecodingContainer where Key : CodingKey { public func decodeIfPresent(codingKey: KeyedDecodingContainer.Key) throws -> MoleculeProtocol? { return try decodeIfPresent(codingKey: codingKey, typeCodingKey: TypeCodingKey.moleculeName) } + + public func decodeArray(codingKey: KeyedDecodingContainer.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.Key) throws -> [MoleculeProtocol]? { + return try decodeArrayIfPresent(codingKey: codingKey, typeCodingKey: TypeCodingKey.moleculeName) as? [MoleculeProtocol] + } }