项目作者: zafarivaev

项目描述 :
Xcode File Template for generating VIPER modules: View, Interactor, Presenter, and Router. Written in Swift 5
高级语言:
项目地址: git://github.com/zafarivaev/VIPER-Template.git
创建时间: 2020-01-01T10:34:25Z
项目社区:https://github.com/zafarivaev/VIPER-Template

开源协议:

下载


VIPER Template

Xcode File Template for generating VIPER modules: View, Interactor, Presenter, and Router. Written in Swift 5

How To Install

  1. Clone the repository
  2. Navigate to Xcode Templates folder: ~/Library/Developer/Xcode/Templates/. If Templates folder doesn’t exist, create it
  3. Copy and paste the VIPER Module.xctemplate in Templates folder

Use

  1. Open Xcode
  2. File -> New -> File or ⌘ N
  3. Scroll down till you see VIPER Module template and choose it.
  4. Set a name for your module. Examples: Home, Auth, SignIn

Generated Code

Let’s suppose we wanted to create the Auth module. Here’s how it would look:

Contract

  1. ```swift
  2. import Foundation
  3. // MARK: View Output (Presenter -> View)
  4. protocol PresenterToViewAuthProtocol {
  5. }
  6. // MARK: View Input (View -> Presenter)
  7. protocol ViewToPresenterAuthProtocol {
  8. var view: PresenterToViewAuthProtocol? { get set }
  9. var interactor: PresenterToInteractorAuthProtocol? { get set }
  10. var router: PresenterToRouterAuthProtocol? { get set }
  11. }
  12. // MARK: Interactor Input (Presenter -> Interactor)
  13. protocol PresenterToInteractorAuthProtocol {
  14. var presenter: InteractorToPresenterAuthProtocol? { get set }
  15. }
  16. // MARK: Interactor Output (Interactor -> Presenter)
  17. protocol InteractorToPresenterAuthProtocol {
  18. }
  19. // MARK: Router Input (Presenter -> Router)
  20. protocol PresenterToRouterAuthProtocol {
  21. }

View

  1. ```swift
  2. import UIKit
  3. class AuthViewController: UIViewController {
  4. // MARK: - Properties
  5. var presenter: ViewToPresenterAuthProtocol?
  6. // MARK: - Lifecycle Methods
  7. override func viewDidLoad() {
  8. super.viewDidLoad()
  9. }
  10. }
  11. extension AuthViewController: PresenterToViewAuthProtocol{
  12. // TODO: Implement View Output Methods
  13. }

Interactor

  1. ```swift
  2. import Foundation
  3. class AuthInteractor: PresenterToInteractorAuthProtocol {
  4. // MARK: Properties
  5. var presenter: InteractorToPresenterAuthProtocol?
  6. }

Presenter

  1. ```swift
  2. import Foundation
  3. class AuthPresenter: ViewToPresenterAuthProtocol {
  4. // MARK: Properties
  5. var view: PresenterToViewAuthProtocol?
  6. var interactor: PresenterToInteractorAuthProtocol?
  7. var router: PresenterToRouterAuthProtocol?
  8. }
  9. extension AuthPresenter: InteractorToPresenterAuthProtocol {
  10. }

Router

  1. ```swift
  2. import Foundation
  3. import UIKit
  4. class AuthRouter: PresenterToRouterAuthProtocol {
  5. // MARK: Static methods
  6. static func createModule() -> UIViewController {
  7. let viewController = AuthViewController()
  8. let presenter: ViewToPresenterQuotesProtocol & InteractorToPresenterQuotesProtocol = AuthPresenter()
  9. viewController.presenter = presenter
  10. viewController.presenter?.router = AuthRouter()
  11. viewController.presenter?.view = viewController
  12. viewController.presenter?.interactor = AuthInteractor()
  13. viewController.presenter?.interactor?.presenter = presenter
  14. return viewController
  15. }
  16. }