Swift 5는 템플릿을 사용하여 VIPER 아키텍처 코드를 자동으로 생성합니다.

기술

VIPER 아키텍처를 생성하기 위해 XCode 수동 생성은 더 번거롭고 오류가 발생하기 쉽습니다. 자동화 된 방식으로 생성하는 것을 생각하는 것은 당연하며 템플릿으로 생성 할 수 있습니다.
여기에 사진 설명 삽입

1. 설치 방법

  1. 저장소 https://github.com/zafarivaev/VIPER-Template을 복제합니다.
  2. Xcode Templates 폴더로 이동합니다. ~ / Library / Developer / Xcode / Templates /. "Templates"폴더가 없으면 만듭니다.
  3. VIPER Module.xctemplate을 Templates 폴더에 복사하여 붙여 넣습니다.

2. 사용

  1. Xcode 열기
  2. 파일-> 새로 만들기-> 파일 또는 ⌘ N
  3. VIPER 모듈 템플릿이 보일 때까지 아래로 스크롤하여 선택합니다.
  4. 모듈의 이름을 설정하십시오. 예 : 홈, 인증, 로그인

여기에 사진 설명 삽입

여기에 사진 설명 삽입

3. 생성 된 코드는 다음과 같습니다.

3.1 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 {
    
    
    
}

3.2 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
}
Interactor
AuthInteractor.swift

import Foundation

class AuthInteractor: PresenterToInteractorAuthProtocol {
    
    

    // MARK: Properties
    var presenter: InteractorToPresenterAuthProtocol?
}

3.3 AuthPresenter.swift

import Foundation

class AuthPresenter: ViewToPresenterAuthProtocol {
    
    

    // MARK: Properties
    var view: PresenterToViewAuthProtocol?
    var interactor: PresenterToInteractorAuthProtocol?
    var router: PresenterToRouterAuthProtocol?
}

extension AuthPresenter: InteractorToPresenterAuthProtocol {
    
    
    
}

3.4 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
    }
    
}

참고

https://github.com/zafarivaev/VIPER-Template

Xcode 템플릿 생성
https://medium.com/overapp-ios/create-xcode-templates-c968d4b43f7b

추천

출처blog.csdn.net/zgpeace/article/details/113094876