ViperMcFlurrySwiftFix1.0.2

ViperMcFlurrySwiftFix1.0.2

测试已测试
Lang语言 SwiftSwift
许可证 MIT
发布最后发布2020 年 11 月
SPM支持 SPM

Siarhei Ladzeika 维护。



  • Siarhei Ladzeika

ViperMcFlurrySwiftFix

目的

包含修复,使 Swift 语言能使用 ViperMcFlurry(《https://github.com/rambler-digital-/solutions/ViperMcFlurry》)功能,解决与 Objective-C 编写的模块交互的 “moduleInput” 问题。

安装

CocoaPods

只需将以下内容添加到您的 Podfile 文件

pod 'ViperMcFlurrySwiftFix'

然后运行:

pod install

它是如何工作的

示例应用程序包含两个 viper 模块 RootTest。Root 模块的 Router 使用 ViperMcFlurry 方法打开 Test 模块。

import ViperMcFlurry

class RootRouter: RootRouterInput {
    
    weak var transitionHandler: RamblerViperModuleTransitionHandlerProtocol!

    func showTest() {
        transitionHandler.openModule!(usingFactory: TestModuleConfigurator()) { (sourceModuleTransitionHandler, destinationModuleTransitionHandler) in
            
            let sourceViewController = sourceModuleTransitionHandler as! UIViewController
            let destinationViewController = destinationModuleTransitionHandler as! UIViewController
            
            sourceViewController.present(destinationViewController, animated: true, completion: nil)
            
            }.thenChain { (moduleInput) -> RamblerViperModuleOutput? in
                // This code without ViperMcFlurrySwiftFix will crash, because
                // moduleInput will check only Obj-C version of property and returns nil.
                // The fix checks both Obj-C and Swift properties.
                (moduleInput as! TestModuleInput).configure()  // FIX WORKS HERE!!!
                return nil
        }
    }
    
}

未修复时,moduleInput 属性在 Obj-C 运行时内部找不到值,因为 Swift 属性并不在那里。所以,首先需要在正常的 Obj-C 属性中进行检查,然后使用 Swift 反射检查 Swift 属性。