diff --git a/MVMCore/MVMCore/Models/Extensions/Decoder.swift b/MVMCore/MVMCore/Models/Extensions/Decoder.swift index 69a0aa8..5435b1d 100644 --- a/MVMCore/MVMCore/Models/Extensions/Decoder.swift +++ b/MVMCore/MVMCore/Models/Extensions/Decoder.swift @@ -35,6 +35,15 @@ extension KeyedDecodingContainerProtocol { } extension Decodable { + public static func decode(jsonDict: [String: Any]) throws -> Self { + let jsonData = try JSONSerialization.data(withJSONObject: jsonDict) + do { + return try jsonData.decode() + } catch { + throw JSONError.other(error: error) + } + } + public static func decode(fileName: String, bundle: Bundle = Bundle.main) throws -> Self { guard let path = bundle.path(forResource: fileName, ofType: ".json") else { throw JSONError.pathNotFound diff --git a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift index a141ed4..719167d 100644 --- a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift +++ b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift @@ -22,6 +22,10 @@ public struct ModelRegistry { public static func register(_ type: M.Type) { types[M.identifier] = type } + + public static func getType(for name: String) -> Model.Type? { + return types[name] + } } extension KeyedDecodingContainer where Key: CodingKey { @@ -50,6 +54,7 @@ extension KeyedDecodingContainer where Key: CodingKey { //get the type guard let found = ModelRegistry.types[type] else { + MVMCoreLoggingHandler.logDebugMessage(withDelegate: "Model not mapped: \(type)") throw ModelRegistry.Error.decoderErrorModelNotMapped }