家政服务如何提升家庭生活质量与幸福感
604
2022-10-13
SwiftyVIPER - 允许在整个iOS应用程序中轻松使用VIPER架构
SwiftyVIPER
SwiftyVIPER allows easy use of VIPER architecture throughout your iOS application.
VIPER Architecture
What is VIPER? Great question! VIPER is a backronym which stands for:
ViewInteractorPresenterEntityRouter
If all of this is totally new for you, check out my running list of VIPER Resources
Features
VIPER Module Templates VIPER Unit Test Templates Simple Module Initialization and Presentation CocoaPods Support Carthage Support
Requirements
iOS 8.0+ | tvOS 9.0+Xcode 9Swift 4
Installation
CocoaPods
You can use CocoaPods to install SwiftyVIPER by adding it to your Podfile:
source 'https://github.com/CocoaPods/Specs.git'use_frameworks!platform :ios, '8.0'def shared_pods pod 'SwiftyVIPER', '~> 1.0'endtarget 'MyApp' do shared_podsendtarget 'MyAppTests' do shared_podsend
To get the full benefits import SwiftyVIPER wherever you import UIKit
import UIKitimport SwiftyVIPER
Carthage
Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.
You can install Carthage with Homebrew using the following command:
brew updatebrew install carthage
To integrate SwiftyVIPER into your Xcode project using Carthage, specify it in your Cartfile:
github "codytwinton/SwiftyVIPER" ~> 1.0
Run carthage update to build the framework and drag the built SwiftyVIPER.framework into your Xcode project.
Manually
This is discouraged, but allowed. :D
Download and drop the Source folder in your project.Congratulations!
Usage of SwiftyVIPER
Installing Templates
If you're looking for VIPER architecture templates to use directly within Xcode, you can find these in the /Templates/VIPER folder. Open your terminal and run:
cd PATH/TO/REPO
Then, simply run this command in your terminal:
mkdir -p ~/Library/Developer/Xcode/Templates/File\ Templatescp -R Templates/VIPER ~/Library/Developer/Xcode/Templates/File\ Templates
Adding a Module
Once you've installed the VIPER Templates, you're ready to add a module. Select File > New > File or use press ⌘N to bring up the template selector. You'll find the templates at the bottom.
Choose Module for a normal module, Module Storyboard for a normal module that interacts with Storyboards, or Module Tests for a module unit tests template.
![Choice](Assets/Template Choice.png)
Next, choose the Module name. We'll go with Custom.
![Name](Assets/Template Name.png)
This will create 5 files per module:
CustomModule.swiftCustomViewController.swiftCustomPresenter.swiftCustomRouter.swiftCustomInteractor.swift
Don't forget to target your main app. Once you've added the main template, go ahead and add the Unit Test template. Make sure it's the same name! In this case, we'd stay with Custom.
Using SwiftyVIPER
Simply add a new module using the VIPER template. Once done, simply call:
import SwiftyVIPERCustomModule().present(from: self.viewController, style: .coverVertical, completion: nil)
The module will handle the rest, including initializing and attaching all the connections necessary for the Module to show properly.
Contribute
We would love for you to contribute to SwiftyVIPER, check the LICENSE file for more info. Pull Requests welcome!
Resources
mutualmobile.comobjc.iockl.iostackoverflow.comyalantis.commedium.comspeakerdeck.combrigade.engineering
Meta
Cody Winton – @codytwintonDistributed under the MIT license. See [LICENSE][license-url] for more information.Inspired by ViperMcFlurryREADME edited with StackEdit
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~