ABOUT ME

Swift가 좋은 개발자입니다. 평생 iOS 개발하면 행복할것 같습니다.

Today
Yesterday
Total
  • Ribs - 로그인편
    Swift/아키텍쳐 2021. 10. 15. 16:36

    위를 이어서 진행하고 있습니다. 이전편 : https://kkimin.tistory.com/89

     

    Ribs 예제 도입기 - Root편

    https://github.com/uber/RIBs/wiki 이거를 그대로 따라가면서 Root, LoggedIn 을 만들어 보자! 아 예제로 이런걸 구현하는구나 한눈에 이해한뒤,. 순서대로 1. Root 를 생성한다. 2. AppDelegate에서 호출 func..

    kkimin.tistory.com

    우버와 달리 login에 input은 하나만 넣어서 진행할 예정이다. 로그인에 통신 쪽까지 구현해보고 싶어서 다른건 좀 덜어내고 할 예정이다.

     

    먼저 RootBuilder에서 Router, Interactor, View, Component를 모두 생성하고 DI를 정의합니다.

     

    RootRouter에서 LoginBuilder를 구성하는데 이때 필요한 LoginBuilder를 작성하러 떠난다.

    protocol RootViewControllable: ViewControllable {
        // TODO: Declare methods the router invokes to manipulate the view hierarchy.
    }
    
    final class RootRouter: LaunchRouter<RootInteractable, RootViewControllable>, RootRouting {
    
        // TODO: Constructor inject child builder protocols to allow building children.
        override init(interactor: RootInteractable, viewController: RootViewControllable) {
            super.init(interactor: interactor, viewController: viewController)
            interactor.router = self
        }
    }

    Todo 를 이해하면 다음 Step 이 쉬워진다.

    protocol RootViewControllable: ViewControllable {
        func present(viewController: ViewControllable)
        func dismiss(viewController: ViewControllable)
    }
    
    final class RootRouter: LaunchRouter<RootInteractable, RootViewControllable>, RootRouting {
    
        init(interactor: RootInteractable,
             viewController: RootViewControllable,
             loggedInBuilder: LoggedInBuildable) {
            self.loggedInBuilder = loggedInBuilder
            super.init(interactor: interactor, viewController: viewController)
            interactor.router = self
        }
        }

     

    RootInteractor 에서는 didLogin 이라는 로직을 구성한다. 

     

    Component 구현하는 쪽

    protocol LoginDependency: Dependency {
        // TODO: Declare the set of dependencies required by this RIB, but cannot be
        // created by this RIB.
    }
    
    // 아래처럼
    protocol LoginDependency: Dependency {
    	var loginViewController: LoginViewControllable { get }
    }

    stream을 활용해서 통신을 하는걸 확인을 해야됨

     

    build 함수 실행시 interactor 를 넣으면 "Argument type 'RootInteractable' does not conform to expected type 'LoginListener'" 오류가 발생합니다. 아래와 같이 RootInteractable 에 LoginListener프로토콜을 상속 받아야 해요.

    728x90

    'Swift > 아키텍쳐' 카테고리의 다른 글

    Redux Architecture (ReSwift)  (0) 2021.11.18
    Ribs 예제 도입기 - Root편  (0) 2021.10.15
    Ribs 예제 도입기 - Ribs 설치 편  (0) 2021.10.15
    Ribs 에 대해서...  (0) 2021.09.30
    Clean Architecture  (0) 2021.06.18

    댓글

Designed by Tistory.