Notice
Recent Posts
Recent Comments
Link
관리 메뉴

김종권의 iOS 앱 개발 알아가기

[iOS - swift] 5. RIBs 프로젝트 초기 세팅 (with cocoapod) 본문

Architecture (swift)/RIBs

[iOS - swift] 5. RIBs 프로젝트 초기 세팅 (with cocoapod)

jake-kim 2021. 4. 28. 23:30

RIBs 설치

  • 프로젝트 생성

  • pod 설치
    - pod 'RIBs'할 경우 RxSwift버전은 4.x버전으로 설최되므로, tag를 명시하여 RxSwift 5.x버전이 받아지도록 설정
pod 'RIBs', :git => 'https://github.com/uber/RIBs.git', :tag => '0.9.2'

storyboard, SceneDelegate 삭제

  • storyboard 삭제
    • Main.storyboard 삭제
    • target의 main interface 에서 설정된 스토리보드 해제
  • SceneDelegate 삭제
    • SceneDelegate.swift 삭제
    • info.plist에 Application Scene Manifest 삭제
    • AppDelegate.swift에 UISsceneSession Lifecycle 관련 메소드 2개 삭제

세팅 완료

RIBs 세팅

  • Root RIB 생성

  • AppComponent 추가, AppStart 그룹 하위로 AppDelegate도 이동

// AppComponent.swift

import RIBs

class AppComponent: Component<EmptyDependency>, RootDependency {

    init() {
        super.init(dependency: EmptyComponent())
    }
}

Root이므로 builder를 생성할 때 listener 파라미터 제거

  • RootBuilder.swift
    • build 함수의 파라미터 제거
    • build 함수의 반환값 변경: RootRouting -> LaunchRouting
// RootBuilder.swift

...

protocol RootBuildable: Buildable {
//    func build(withListener listener: RootListener) -> RootRouting
    func build() -> LaunchRouting
}

final class RootBuilder: Builder<RootDependency>, RootBuildable {

    override init(dependency: RootDependency) {
        super.init(dependency: dependency)
    }

    func build() -> LaunchRouting {
        let component = RootComponent(dependency: dependency)
        let viewController = RootViewController()
        let interactor = RootInteractor(presenter: viewController)

        return RootRouter(interactor: interactor, viewController: viewController)
    }
}

 

  • RootRouter.swift가 상속받고 있는 ViewableRouter를 LaunchRouter로 수정
// RootRouter.swift

...

final class RootRouter: LaunchRouter<RootInteractable, RootViewControllable>, RootRouting {

    override init(interactor: RootInteractable, viewController: RootViewControllable) {
        super.init(interactor: interactor, viewController: viewController)
        interactor.router = self
    }
}

AppDelegate에서 RootBuilder를 통해 LaunchRouter 객체 획득

import UIKit
import RIBs

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

        let window = UIWindow(frame: UIScreen.main.bounds)
        self.window = window

        let launchRouter = RootBuilder(dependency: AppComponent()).build()
        self.launchRouter = launchRouter

        launchRouter.launch(from: window)

        return true
    }

    // MARK: - Private

    private var launchRouter: LaunchRouting?
}

* 빌드 성공 확인

Comments