unify the mappings

This commit is contained in:
Pfeil, Scott Robert 2021-03-31 14:00:11 -04:00
parent 31ccb1ecd2
commit 65c71d6ff8
2 changed files with 18 additions and 4 deletions

View File

@ -66,7 +66,15 @@ extension MoleculeViewProtocol {
public extension ModelRegistry {
/// Returns the type of molecule view for the given model
static func getMoleculeClass(_ model: MoleculeModelProtocol) -> MoleculeViewProtocol.Type? {
return ModelRegistry.getHandler(model) as? MoleculeViewProtocol.Type
do {
let type = try ModelRegistry.getHandler(model) as! MoleculeViewProtocol.Type
return type
} catch {
if let errorObject = MVMCoreErrorObject.createErrorObject(for: error, location: #function) {
MVMCoreLoggingHandler.shared()?.addError(toLog: errorObject)
}
return nil
}
}
/// Creates a molecule with the given model.

View File

@ -21,9 +21,15 @@ public extension PageBehaviorHandlerProtocol {
}
var behaviors: [PageBehaviorProtocol] = []
for behaviorModel in behaviorModels {
guard let handlerType = ModelRegistry.getHandler(behaviorModel) as? PageBehaviorProtocol.Type else { continue }
let behavior = handlerType.init(model: behaviorModel, delegateObject: delegateObject)
behaviors.append(behavior)
do {
let handlerType = try ModelRegistry.getHandler(behaviorModel) as! PageBehaviorProtocol.Type
let behavior = handlerType.init(model: behaviorModel, delegateObject: delegateObject)
behaviors.append(behavior)
} catch {
if let errorObject = MVMCoreErrorObject.createErrorObject(for: error, location: #function) {
MVMCoreLoggingHandler.shared()?.addError(toLog: errorObject)
}
}
}
self.behaviors = behaviors.count > 0 ? behaviors : nil
}