20220207 iOS 일일 개발일지 === ###### tags: `develop` HomeViewController을 DI가 가능한 구조로 구성하는 과정에서 필요한 상속 구조를 따르도록 코드를 변경 중임. 배너 자동 스크롤에 대한 코드를 임시적으로 제외시켰다. ```swift= extension HomeViewController { func bannerTimer() { let _: Timer = Timer.scheduledTimer(withTimeInterval: 2, repeats: true) { (Timer) in self.bannerMove() } } func bannerMove() { currentIndex += 1 homeView.homeCollectionView.scrollToItem(at: NSIndexPath(item: currentIndex, section: 0) as IndexPath, at: .bottom, animated: true) if self.currentIndex == self.banners.count-1 { DispatchQueue.main.asyncAfter(deadline: .now() + 0.28) { self.scrollTofirstIndex() } } } func scrollTofirstIndex() { homeView.homeCollectionView.scrollToItem(at: NSIndexPath(item: 0, section: 0) as IndexPath, at: .top, animated: false) currentIndex = 0 } } ``` ### **동일한 repository에 접근하더라도, protocol을 활용해 접근 권한에 제한을 두는 방법을 생각해보고 구성했음.** #### 🚨 같은 Repository class의 Extension을 활용해 접근하는 protocol의 기능에 맞는 역할에 대한 세부구현만을 접근할 수 있도록 하기. ProductRepository에 접근하도록 하지만, HomeView에서 굳이 ProductList에서 요구되는 function들을 알 필요가 없다. 따라서 ProductRepository에 접근하는 경우는 하단처럼 두 가지로 나눌 수 있다. ```swift= extension ProductRepository: ProductRepositoryInterface { func requestProducts(page: Int, category: String?, completion: @escaping ((Result<Products, Error>) -> Void)) -> Cancellable { ... } func requestProductById(_ id: Int, completion: @escaping ((Result<ProductDetail, Error>) -> Void)) -> Cancellable { ... } } // MARK: Home View Repository Interface extension ProductRepository: HomeListRepositoryInterface { func fetchHome(completion: @escaping ((Result<HomeInfo, Error>) -> Void)) -> Cancellable { ... } } ``` HomeListRepositoryInterface의 타입으로 불러오느냐. ProductRepositoryInterface의 타입으로 불러오느냐에 따라 접근할 수 있는 메서드를 제한해서 구현 UML로 그리면 다음과 같이 표현할 수 있음. ![](https://i.imgur.com/n5gQVAl.png)