ViperMcFlurry 1.5.2

ViperMcFlurry 1.5.2

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
发布上次发布2016年10月

Andrey Zarembo[etolstoy] 维护。



  • Andrey Zarembo-Godzyatsky 和 Valery Popov

概览

Pod version

VIPER McFlurry 是一个现代框架,用于在 iOS 应用中实现 VIPER 架构。它提供了一些工具和组件,帮助您使用 VIPER 或从 MVC 迁移到开始新项目。

McFlurry

主要功能

  • 该框架本身鼓励您实现一个 合适的 VIPER 架构
  • 它提供了一种非常好且简单的方法来实现 模块间数据传输
  • 默认的 Generamba 模板 中使用。

用法

此示例仅适用于具有 UIViewController 作为视图的模块。然而,即使在 UIViewUITableViewCell 作为视图的情况下,也可以使用这种方法。

  • 为目标模块创建继承自 RamblerViperModuleInput 的模块输入协议
@protocol SomeModuleInput <RamblerViperModuleInput>

- (void)moduleConfigurationMethod;

@end
  • 让目标模块的 Presenter 接受此协议。
  • 将 Presenter 注入为视图的 moduleInput 属性。如果您需要将 Presenter 作为名为 "output" 的视图属性,则可以跳过此步骤。
  • 从源模块 ViewController 到目标模块 ViewController 添加 Segue。
  • 将 Source ViewController 注入到 Source Router 中,作为属性 "transition handler"。
  • 在 Router 中调用 transition handler 在 segue 期间配置并打开目标模块。
[[self.transitionHandler openModuleUsingSegue:SegueIdentifier]
    thenChainUsingBlock:^id<RamblerViperModuleOutput>(id<SomeModuleInput> moduleInput) {
        [moduleInput moduleConfigurationMethod];
        return nil;
    }];

处理模块输出

  • 为目标模块创建继承自 RamblerViperModuleOutput 的模块输出协议
@protocol SomeModuleOutput <RamblerViperModuleOutput>

- (void)moduleConfigurationMethod;

@end
  • 使源模块的 Presenter 接受此协议。
  • 在目标模块 Presenter 中添加方法
- (void)setModuleOutput:(id<RamblerViperModuleOutput>)moduleOutput;
  • 从路由器中的配置块返回源模块 Presenter
[[self.transitionHandler openModuleUsingSegue:SegueIdentifier]
    thenChainUsingBlock:^id<RamblerViperModuleOutput>(id<SomeModuleInput> moduleInput) {
        [moduleInput moduleConfigurationMethod];
        return sourceRouterPresenter; // Return of module output
    }];

处理模块工厂

在大多数情况下,可以将模块工厂与 segues 替换。除了一种情况:您需要创建复杂的模块或非平凡模块实例化逻辑。

  • 使用 Typhoon 中的 RamblerViperModuleFactory 对象作为模块模型。
  • 将定义初始化器设置为 initWithStoryboard:andRestorationId:
    • 第一个参数是 UIStoryboard 实例,
    • 第二个参数是 ViewController 的 RestorationID。
  • Typhoon 会从 ViewController 中初始化模块。
  • 将此工厂注入到路由器中。
  • 调用转换处理器的- openModuleUsingFactory:withTransitionBlock:方法。
  • 第二个块是执行从其中一个到另一个viewController/转换处理器的转换应该进行的地点。
    [[self.transitionHandler openModuleUsingFactory:self.betaModuleFactory
                                withTransitionBlock:^(id <RamblerViperModuleTransitionHandlerProtocol> sourceModuleTransitionHandler,
                                        id <RamblerViperModuleTransitionHandlerProtocol> destinationModuleTransitionHandler) {

                                    UIViewController *sourceViewController = (id) sourceModuleTransitionHandler;
                                    UIViewController *destinationViewController = (id) destinationModuleTransitionHandler;

                                    [sourceViewController.navigationController pushViewController:destinationViewController
                                                                                         animated:YES];

                                }] thenChainUsingBlock:^id<RamblerViperModuleOutput>(id<RamblerModuleBetaInput> moduleInput) {
                                   [moduleInput configureWithExampleString:exampleString];
                                   return nil;
                               }];
  • 在上面的例子中,一个模块被推到另一个模块的导航堆栈中。
  • 模块通过模块间数据传输块相互连接。

安装

添加到Podfile

pod "ViperMcFlurry"

许可证

MIT

作者

Rambler&Co团队