Xcode File Template for generating VIPER modules: View, Interactor, Presenter, and Router. Written in Swift 5 Forked from zafarivaev and install using the script of Juanpe. Added other 2 styles of VIPER.
Only need execute this command in terminal:
sudo swift install.swift
Go to Application folder, browse to the Xcode application icon. Right-click it and choose 'Show Package Contents'. Then browse to:
Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/Project Templates/iOS/Application
and add "Module VIPER.xctemplate" file. Now you can find your template in Xcode.
- Open Xcode
File -> New -> File
or⌘ N
- Scroll down till you see
VIPER Module
template and choose it. - Set a name for your module. Examples:
Home, Auth, SignIn
Let's suppose we wanted to create the Auth module. Here's how it would look:
AuthContract.swift
import Foundation
// MARK: View Output (Presenter -> View)
protocol PresenterToViewAuthProtocol {
}
// MARK: View Input (View -> Presenter)
protocol ViewToPresenterAuthProtocol {
var view: PresenterToViewAuthProtocol? { get set }
var interactor: PresenterToInteractorAuthProtocol? { get set }
var router: PresenterToRouterAuthProtocol? { get set }
}
// MARK: Interactor Input (Presenter -> Interactor)
protocol PresenterToInteractorAuthProtocol {
var presenter: InteractorToPresenterAuthProtocol? { get set }
}
// MARK: Interactor Output (Interactor -> Presenter)
protocol InteractorToPresenterAuthProtocol {
}
// MARK: Router Input (Presenter -> Router)
protocol PresenterToRouterAuthProtocol {
}
AuthViewController.swift
import UIKit
class AuthViewController: UIViewController {
// MARK: - Properties
var presenter: ViewToPresenterAuthProtocol?
// MARK: - Lifecycle Methods
override func viewDidLoad() {
super.viewDidLoad()
}
}
extension AuthViewController: PresenterToViewAuthProtocol{
// TODO: Implement View Output Methods
}
AuthInteractor.swift
import Foundation
class AuthInteractor: PresenterToInteractorAuthProtocol {
// MARK: Properties
var presenter: InteractorToPresenterAuthProtocol?
}
AuthPresenter.swift
import Foundation
class AuthPresenter: ViewToPresenterAuthProtocol {
// MARK: Properties
var view: PresenterToViewAuthProtocol?
var interactor: PresenterToInteractorAuthProtocol?
var router: PresenterToRouterAuthProtocol?
}
extension AuthPresenter: InteractorToPresenterAuthProtocol {
}
AuthRouter.swift
import Foundation
import UIKit
class AuthRouter: PresenterToRouterAuthProtocol {
// MARK: Static methods
static func createModule() -> UIViewController {
let viewController = AuthViewController()
let presenter: ViewToPresenterQuotesProtocol & InteractorToPresenterQuotesProtocol = AuthPresenter()
viewController.presenter = presenter
viewController.presenter?.router = AuthRouter()
viewController.presenter?.view = viewController
viewController.presenter?.interactor = AuthInteractor()
viewController.presenter?.interactor?.presenter = presenter
return viewController
}
}