From 29c73f2ccc883370b0295b433e8cdbc8339caaa0 Mon Sep 17 00:00:00 2001 From: Sumanth Nadigadda Date: Wed, 22 Feb 2023 23:19:57 +0530 Subject: [PATCH] Making the shouldFinishProcessingLoad method in behavior to throw --- .../BaseControllers/ViewController.swift | 21 ++++++++++++------- .../PageBehaviorHandlerProtocol.swift | 4 ++-- .../Protocols/PageBehaviorProtocol.swift | 4 ++-- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/MVMCoreUI/BaseControllers/ViewController.swift b/MVMCoreUI/BaseControllers/ViewController.swift index cab9d9ce..dddb918e 100644 --- a/MVMCoreUI/BaseControllers/ViewController.swift +++ b/MVMCoreUI/BaseControllers/ViewController.swift @@ -146,15 +146,20 @@ import MVMCore } } - ///Check with behavior if it can continue - let conditionSatisfied = conditionSatisfyingBehaviours { (behavior: PageMoleculeTransformationBehavior) in - return behavior.shouldFinishProcessingLoad(loadObject) + ///Check with behavior if it can continue + do{ + let conditionSatisfied = try executeThrowingBehaviors {(behavior: PageMoleculeTransformationBehavior) in + return try behavior.shouldFinishProcessingLoad(loadObject) + } + if conditionSatisfied == false { + return conditionSatisfied + } + } catch let behaviorError { + if let errorObject = MVMCoreErrorObject.createErrorObject(for: behaviorError, location: MVMCoreLoadHandler.sharedGlobal()?.errorLocation(forRequest: loadObject)) { + error.pointee = errorObject + } } - - if conditionSatisfied == false { - return conditionSatisfied - } - + return true } diff --git a/MVMCoreUI/Behaviors/Protocols/PageBehaviorHandlerProtocol.swift b/MVMCoreUI/Behaviors/Protocols/PageBehaviorHandlerProtocol.swift index dcd8a2eb..b0d49b69 100644 --- a/MVMCoreUI/Behaviors/Protocols/PageBehaviorHandlerProtocol.swift +++ b/MVMCoreUI/Behaviors/Protocols/PageBehaviorHandlerProtocol.swift @@ -45,7 +45,7 @@ public extension PageBehaviorHandlerProtocol { behaviors?.compactMap { $0 as? T }.forEach { behaviorBlock($0) } } - func conditionSatisfyingBehaviours(_ behaviourBlock: (_ behavior: T) -> Bool) -> Bool { - return behaviors?.compactMap({$0 as? T}).allSatisfy({ return behaviourBlock($0) }) ?? false + func executeThrowingBehaviors(_ behaviourBlock: (_ behavior: T) throws -> Bool) throws -> Bool { + return try behaviors?.compactMap({$0 as? T}).allSatisfy({ return try behaviourBlock($0) }) ?? false } } diff --git a/MVMCoreUI/Behaviors/Protocols/PageBehaviorProtocol.swift b/MVMCoreUI/Behaviors/Protocols/PageBehaviorProtocol.swift index c8b05055..543ee60c 100644 --- a/MVMCoreUI/Behaviors/Protocols/PageBehaviorProtocol.swift +++ b/MVMCoreUI/Behaviors/Protocols/PageBehaviorProtocol.swift @@ -32,7 +32,7 @@ public protocol PageMoleculeTransformationBehavior: PageBehaviorProtocol { func didSetupMolecule(view: MoleculeViewProtocol, withModel: MoleculeModelProtocol) func willSetupNavigationBar(with model: NavigationItemModelProtocol, updating view: UINavigationBar) func didSetupNavigationBar(view: UINavigationBar, with model: NavigationItemModelProtocol) - func shouldFinishProcessingLoad(_ loadObject: MVMCoreLoadObject) -> Bool + func shouldFinishProcessingLoad(_ loadObject: MVMCoreLoadObject) throws -> Bool } public extension PageMoleculeTransformationBehavior { @@ -42,7 +42,7 @@ public extension PageMoleculeTransformationBehavior { func didSetupMolecule(view: MoleculeViewProtocol, withModel: MoleculeModelProtocol) {} func willSetupNavigationBar(with model: NavigationItemModelProtocol, updating view: UINavigationBar) {} func didSetupNavigationBar(view: UINavigationBar, with model: NavigationItemModelProtocol) {} - func shouldFinishProcessingLoad(_ loadObject: MVMCoreLoadObject) -> Bool { return true } + func shouldFinishProcessingLoad(_ loadObject: MVMCoreLoadObject) throws -> Bool { return true } } public protocol PageVisibilityBehavior: PageBehaviorProtocol {