diff --git a/MVMCoreUI/Models/Extensions/ModelHelper.swift b/MVMCoreUI/Models/Extensions/ModelHelper.swift index fc0616c1..7c73f264 100644 --- a/MVMCoreUI/Models/Extensions/ModelHelper.swift +++ b/MVMCoreUI/Models/Extensions/ModelHelper.swift @@ -13,14 +13,17 @@ extension KeyedDecodingContainer where Key : CodingKey { case moleculeName } + /// Decodes the molecule model with the given coding key based on moleculeName public func decodeMolecule(codingKey: KeyedDecodingContainer.Key) throws -> MoleculeProtocol { return try decodeModel(codingKey: codingKey, typeCodingKey: TypeCodingKey.moleculeName) } + /// Decodes the molecule model with the given coding key based on moleculeName, optional public func decodeMoleculeIfPresent(codingKey: KeyedDecodingContainer.Key) throws -> MoleculeProtocol? { return try decodeModelIfPresent(codingKey: codingKey, typeCodingKey: TypeCodingKey.moleculeName) } + /// Decodes the list of molecule models with the given coding key based on moleculeName public func decodeMolecules(codingKey: KeyedDecodingContainer.Key) throws -> [MoleculeProtocol] { guard let models = try decodeModels(codingKey: codingKey, typeCodingKey: TypeCodingKey.moleculeName) as? [MoleculeProtocol] else { throw ModelRegistry.Error.decoderError @@ -28,6 +31,7 @@ extension KeyedDecodingContainer where Key : CodingKey { return models } + /// Decodes the list of molecule models with the given coding key based on moleculeName, optional public func decodeMoleculesIfPresent(codingKey: KeyedDecodingContainer.Key) throws -> [MoleculeProtocol]? { return try decodeModelsIfPresent(codingKey: codingKey, typeCodingKey: TypeCodingKey.moleculeName) as? [MoleculeProtocol] }