Merge branch 'feature/molecule_decode_helper' into 'develop'

helper for always present

See merge request BPHV_MIPS/mvm_core_ui!703
This commit is contained in:
Hedden, Kyle Matthew 2021-04-08 13:38:14 -04:00
commit d33cbd94ac

View File

@ -21,6 +21,8 @@ public extension MoleculeModelProtocol {
static var categoryCodingKey: String { "moleculeName" }
}
// Helpers made due to swift not able to reconcile which category.
extension KeyedDecodingContainer where Key: CodingKey {
/// Decodes to a registered molecule based on the identifier
public func decodeMoleculeIfPresent<T>(codingKey: KeyedDecodingContainer<K>.Key) throws -> T? {
@ -33,6 +35,15 @@ extension KeyedDecodingContainer where Key: CodingKey {
}
return modelT
}
/// Decodes to a registered molecule based on the identifier.
public func decodeMolecule<T>(codingKey: KeyedDecodingContainer<K>.Key) throws -> T {
guard let model: T = try decodeMoleculeIfPresent(codingKey: codingKey) else {
MVMCoreLoggingHandler.logDebugMessage(withDelegate: "ModelRegistry Error decoderErrorObjectNotPresent: \(codingKey.stringValue)")
throw ModelRegistry.Error.decoderErrorObjectNotPresent(codingKey: codingKey, codingPath: codingPath)
}
return model
}
}
public extension MoleculeModelProtocol {