Viper是用Swift编写的框架,可以让您更方便、更容易地构建VIPER架构
此组件使VIPER模块之间的转换变得简单
/// With 'present' option
transitionHandler?.openModule(usingFactory: factory, type: SecondModuleInput.self)
.to(preferred: TransitionStyle.present)
.then { moduleInput in
moduleInput.setData(data)
}
/// Or with 'navigationController' options
transitionHandler?.openModule(usingFactory: factory, type: SecondModuleInput.self)
.to(preferred: TransitionStyle.navigationController(navigationStyle: .push))
.then { moduleInput in
moduleInput.setData(data)
}
transitionHandler?.performSegue(segueIdentifier)
/// Or with setup block
transitionHandler?.openModuleUsingSegue(with: segueIdentifier, to: SecondModuleInput.self) { moduleInput in
moduleInput.setData(data)
}
transitionHandler?.closeCurrentModule(true)
此组件可以帮助您显示View的不同状态
/// Start showing progress
view?.startIndication()
/// Stop progress
view?.stopIndication()
/// Show unknown error's message
view?.showError()
/// Show success view
view?.showSuccess()
/// Show the given message
view?.showMessage("Message")
/// Show the given error message
view?.showErrorMessage("Error message")
此组件简化了与组件的工作
class YourModuleAssembly: CollectableAssembly {
required init() {
}
/// Register your dependencies through Swinject.
/// You may not call this method because
/// AssembliesCollector automatically call it :)
func assemble(in container: Container) {
}
}
如何使用InteractorOutput、ContentManager、ModuleInput、ModuleOutput?请看示例 ;)
如果您不希望使用任何依赖关系管理器,您可以手动将 Viper 整合到您的项目中。
打开终端,cd
到您顶级项目目录,并运行以下命令(如果您的项目不是作为 git 仓库初始化)
$ git init
通过以下命令将 Viper 作为 git 子模块 添加
$ git submodule add https://github.com/incetro/Viper.git
打开新的 Viper
文件夹,并将 Viper.xcodeproj
拖动到您的应用程序 Xcode 项目的项目导航器中。
它应该位于您应用程序图标下蓝色项目图标的下方。无论是在所有其他 Xcode 组之上还是之下,并无关系。
在项目导航器中选择 Viper.xcodeproj
,并验证部署目标与应用程序目标相匹配。
然后,在项目导航器(蓝色项目图标)中选择您的应用程序项目,导航到目标配置窗口,并在侧边栏的“目标”标题下选择应用程序目标。
在窗口顶部的标签栏中,打开“通用”面板。
在“嵌入式二进制文件”部分下点击 +
按钮。
您将看到两个不同的 Viper.xcodeproj
文件夹,每个文件夹内都有一个位于“Products”文件夹中的两个不同版本的 Viper.framework
。
您可以选择“Products”文件夹中的任何一个,但必须选择顶部或底部的
Viper.framework
。
选择顶部的 Viper.framework
用于 iOS,底部的用于 OS X。
就是这样!
Viper.framework
将自动添加为目标依赖关系、链接框架和嵌入框架,在复制文件构建阶段完成所有这些操作即可在模拟器和设备上构建。
incetro,[email protected]。灵感来源于 ViperMcFlurry
VIPER 提供在 MIT 许可之下。有关更多信息,请参阅 LICENSE 文件。