Convenience function
This commit is contained in:
parent
e90bf7c9db
commit
fd3f3ea627
@ -34,6 +34,18 @@ import Foundation
|
|||||||
return type.init(model: model, delegateObject, additionalData)
|
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.
|
/// Call to register all of the CoreUI molecules.
|
||||||
public static func registerObjects() {
|
public static func registerObjects() {
|
||||||
// Stacks
|
// Stacks
|
||||||
|
|||||||
@ -93,10 +93,7 @@ import UIKit
|
|||||||
|
|
||||||
/// Convenience setter for legacy files
|
/// Convenience setter for legacy files
|
||||||
public static func set(navigationController: UINavigationController, navigationJSON: [String: Any], viewController: UIViewController) throws {
|
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 {
|
guard let barModel = try MoleculeObjectMapping.shared()?.getMoleculeModelForJSON(navigationJSON) as? (MoleculeModelProtocol & NavigationItemModelProtocol) else {
|
||||||
throw ModelRegistry.Error.keyNotFound
|
|
||||||
}
|
|
||||||
guard let barModel = try moleculeName.decode(jsonDict: navigationJSON) as? (MoleculeModelProtocol & NavigationItemModelProtocol) else {
|
|
||||||
throw ModelRegistry.Error.decoderOther(message: "Model not a bar model")
|
throw ModelRegistry.Error.decoderOther(message: "Model not a bar model")
|
||||||
}
|
}
|
||||||
set(navigationController: navigationController, navigationItemModel: barModel, viewController: viewController)
|
set(navigationController: navigationController, navigationItemModel: barModel, viewController: viewController)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user