use helper function for getting type

This commit is contained in:
Pfeil, Scott Robert 2019-12-18 13:26:15 -05:00
parent 326f761f4f
commit 2b0b4cf91a

View File

@ -54,7 +54,7 @@ extension KeyedDecodingContainer where Key: CodingKey {
} }
//get the type //get the type
guard let type = ModelRegistry.types[identifier] else { guard let type = ModelRegistry.getType(for: identifier) else {
MVMCoreLoggingHandler.logDebugMessage(withDelegate: "Model not mapped: \(identifier)") MVMCoreLoggingHandler.logDebugMessage(withDelegate: "Model not mapped: \(identifier)")
throw ModelRegistry.Error.decoderErrorModelNotMapped throw ModelRegistry.Error.decoderErrorModelNotMapped
} }
@ -80,7 +80,7 @@ extension KeyedDecodingContainer where Key: CodingKey {
let nestedContainer = try container.nestedContainer(keyedBy: C.self) let nestedContainer = try container.nestedContainer(keyedBy: C.self)
if let identifier = try nestedContainer.decodeIfPresent(String.self, forKey: typeCodingKey) { if let identifier = try nestedContainer.decodeIfPresent(String.self, forKey: typeCodingKey) {
//get the type //get the type
guard let type = ModelRegistry.types[identifier] else { guard let type = ModelRegistry.getType(for: identifier) else {
throw ModelRegistry.Error.decoderErrorModelNotMapped throw ModelRegistry.Error.decoderErrorModelNotMapped
} }
//now get the decoder to use for the type //now get the decoder to use for the type