diff --git a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift index 76fc9e4..1089d61 100644 --- a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift +++ b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift @@ -26,14 +26,13 @@ public struct ModelRegistry { extension KeyedDecodingContainer where Key : CodingKey{ - public enum TypeCodingKey: String, CodingKey { - //need to discuss this the enum - case moleculeName + + private enum TypeCodingKey: String, CodingKey { case actionMap } //MARK: - Decode - public func decode(codingKey: KeyedDecodingContainer.Key, typeCodingKey: TypeCodingKey) throws -> T { + public func decode(codingKey: KeyedDecodingContainer.Key, typeCodingKey: C) throws -> T { guard let model: Model = try decodeIfPresent(codingKey: codingKey, typeCodingKey: typeCodingKey) else { throw ModelRegistry.Error.decoderErrorObjectNotPresent } @@ -46,14 +45,14 @@ extension KeyedDecodingContainer where Key : CodingKey{ } public func decode(codingKey: KeyedDecodingContainer.Key) throws -> ActionMapModel { - return try decode(codingKey: codingKey, typeCodingKey: .actionMap) + return try decode(codingKey: codingKey, typeCodingKey: TypeCodingKey.actionMap) } //MARK: - DecodeIfPresent - public func decodeIfPresent(codingKey: KeyedDecodingContainer.Key, typeCodingKey: TypeCodingKey) throws -> T? { + public func decodeIfPresent(codingKey: KeyedDecodingContainer.Key, typeCodingKey: C) throws -> T? { //get the type string - let meta = try self.nestedContainer(keyedBy: TypeCodingKey.self, forKey: codingKey) + let meta = try self.nestedContainer(keyedBy: type(of: typeCodingKey), forKey: codingKey) guard let type = try meta.decodeIfPresent(String.self, forKey: typeCodingKey) else { return nil } @@ -76,7 +75,7 @@ extension KeyedDecodingContainer where Key : CodingKey{ } public func decodeIfPresent(codingKey: KeyedDecodingContainer.Key) throws -> ActionMapModel? { - return try decodeIfPresent(codingKey: codingKey, typeCodingKey: .actionMap) + return try decodeIfPresent(codingKey: codingKey, typeCodingKey: TypeCodingKey.actionMap) } }