20220124 iOS 일일 개발일지 === ###### tags: `develop` [TOC] Segment Control이 실제로 필요하지 않다고 판단되어 제거 진행함. **프로젝트 내 제거 코드** <details> <summary>SegmentControl Code</summary> <div markdown="1"> ```swift= private func configureSegmentedControl() { let navigationSegmentedControl = BetterSegmentedControl( frame: CGRect(x: 0, y: 0, width: 200.0, height: 30.0), segments: LabelSegment.segments(withTitles: ["투데이", "발매정보"], normalTextColor: .systemGray4, selectedTextColor: .black), options:[.backgroundColor(.white), .indicatorViewBackgroundColor(UIColor(red: 0.36, green: 0.38, blue: 0.87, alpha: 1.00)), .cornerRadius(3.0), .animationSpringDamping(1.0), .indicatorViewBorderWidth(1.0) ] ) navigationSegmentedControl.addTarget(self, action: #selector(navigationSegmentedControlValueChanged), for: .valueChanged) navigationItem.titleView = navigationSegmentedControl } @objc func navigationSegmentedControlValueChanged(_ sender: BetterSegmentedControl) { if sender.index == 0 { if #available(iOS 13.0, *) { view.backgroundColor = .systemGray5 } else { view.backgroundColor = .white } } else { view.backgroundColor = .darkGray } } ``` </div> </details> <details> <summary>Compositional Layout</summary> <div markdown="1"> ```swift= private func configureSectionLayout(_ itemSize: NSCollectionLayoutSize, _ itemContentInsets: NSDirectionalEdgeInsets = .init(top: 0, leading: 0, bottom: 0, trailing: 0), _ groupSize: NSCollectionLayoutSize, _ groupContenInsets: NSDirectionalEdgeInsets = .init(top: 0, leading: 0, bottom: 0, trailing: 0), _ supplementaryItems: NSCollectionLayoutBoundarySupplementaryItem...) -> NSCollectionLayoutSection { let item = NSCollectionLayoutItem(layoutSize: itemSize) item.contentInsets = itemContentInsets let group = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize, subitems: [item]) group.contentInsets = groupContenInsets let section = NSCollectionLayoutSection(group: group) section.orthogonalScrollingBehavior = .groupPaging section.contentInsets = NSDirectionalEdgeInsets(top: 10, leading: 5, bottom: 0, trailing: 0) section.boundarySupplementaryItems = [ NSCollectionLayoutBoundarySupplementaryItem(layoutSize: .init(widthDimension: .fractionalWidth(1), heightDimension: .estimated(40)), elementKind: UICollectionView.elementKindSectionHeader, alignment: .topLeading) ] return section } ``` </div> </details> <br> <br> Service Layer을 두고, 모델을 얻기 위해 Repository에 요청하는 방식의 구조를 채택하자. 의존 구조 방향성을 한 방향으로 가져가기 ShopViewController -> ProductViewController 디렉토리 명 변경. --- 현재 각 뷰 별 예상 구조 -> compositional Layout으로 인해 cell에 대한 viewModel이 ![구조 그림](https://i.imgur.com/Dt8M3Lc.png) --- https://stackguides.com/questions/62855991/how-to-prevent-auto-focus-on-collection-view-compositional-layout-swift Clean Architecture 에서 usecase를 적용할 것인지 아니면 Service Layer에 대한 구분만 할 것인지에 대해서도 적용이 필요함 실제 Clean Architecture에 대한 부분은 milestone 1에 해당하지 않기 때문에 일단 MVVM에 대한 패턴을 확실히 하자 ![](https://i.imgur.com/qIrzgm5.png) ![](https://i.imgur.com/ttnUAvr.png) ![](https://i.imgur.com/tkn1xeL.png) ```swift= class EmployeesViewModel: NSObject { private var employeeService: EmployeeServiceProtocol } ``` ![](https://i.imgur.com/MQILOsO.png) https://johncodeos.com/how-to-implement-mvvm-pattern-with-swift-in-ios/