diff --git a/MVMCoreUI/Atomic/MoleculeObjectMapping.swift b/MVMCoreUI/Atomic/MoleculeObjectMapping.swift index ce86fc26..4f151642 100644 --- a/MVMCoreUI/Atomic/MoleculeObjectMapping.swift +++ b/MVMCoreUI/Atomic/MoleculeObjectMapping.swift @@ -34,6 +34,18 @@ import Foundation return type.init(model: model, delegateObject, additionalData) } + /// Convenience function for legacy classes + public func getMoleculeModelForJSON(_ json: [String: Any]) throws -> MoleculeModelProtocol? { + guard let moleculeName = json.optionalStringForKey(KeyMoleculeName), + let type = ModelRegistry.getType(for: moleculeName, with: MoleculeModelProtocol.self) else { + throw ModelRegistry.Error.decoderErrorModelNotMapped + } + guard let model = try type.decode(jsonDict: json) as? MoleculeModelProtocol else { + throw ModelRegistry.Error.decoderError + } + return model + } + /// Call to register all of the CoreUI molecules. public static func registerObjects() { // Stacks diff --git a/MVMCoreUI/Containers/NavigationController.swift b/MVMCoreUI/Containers/NavigationController.swift index 8e7279ce..0d4d0a56 100644 --- a/MVMCoreUI/Containers/NavigationController.swift +++ b/MVMCoreUI/Containers/NavigationController.swift @@ -93,10 +93,7 @@ import UIKit /// Convenience setter for legacy files public static func set(navigationController: UINavigationController, navigationJSON: [String: Any], viewController: UIViewController) throws { - guard let moleculeName = ModelRegistry.getType(for: navigationJSON.stringForkey(KeyMoleculeName), with: MoleculeModelProtocol.self) else { - throw ModelRegistry.Error.keyNotFound - } - guard let barModel = try moleculeName.decode(jsonDict: navigationJSON) as? (MoleculeModelProtocol & NavigationItemModelProtocol) else { + guard let barModel = try MoleculeObjectMapping.shared()?.getMoleculeModelForJSON(navigationJSON) as? (MoleculeModelProtocol & NavigationItemModelProtocol) else { throw ModelRegistry.Error.decoderOther(message: "Model not a bar model") } set(navigationController: navigationController, navigationItemModel: barModel, viewController: viewController)