Skip to content

Commit

Permalink
[Refactor] MainCoordinator 코드 생성 DO-SOPT-iOS-Part#20
Browse files Browse the repository at this point in the history
  • Loading branch information
HELLOHIDI committed Jul 5, 2024
1 parent 66c2503 commit 13165d3
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 73 deletions.
2 changes: 1 addition & 1 deletion Projects/Core/Sources/Protocol/ViewModelType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation

import RxSwift

protocol ViewModelType {
public protocol ViewModelType {

associatedtype Input
associatedtype Output
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// MainFeatureViewBuildable.swift
// MainFeatureInterface
//
// Created by 류희재 on 7/5/24.
// Copyright © 2024 Weather-iOS. All rights reserved.
//

import Core

public protocol MainFeatureViewBuildable {
func makeMain() -> MainPresentable
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,14 @@
//

import Foundation

import BaseFeatureDependency
import Core

public protocol MainViewControllable: ViewControllable { }
public protocol MainCoordinatable {
}
public typealias MainViewModelType = ViewModelType & MainCoordinatable
public typealias MainPresentable = (vc: MainViewControllable, vm: any MainViewModelType)


This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// MainBuilder.swift
// MainFeatureInterface
//
// Created by 류희재 on 7/5/24.
// Copyright © 2024 Weather-iOS. All rights reserved.
//

import Core
import Domain

import MainFeatureInterface

public
final class MainBuilder {
public var repository: WeatherRepository

public init(repository: WeatherRepository) {
self.repository = repository
}
}

extension MainBuilder: MainFeatureViewBuildable {
public func makeMain() -> MainPresentable {
let useCase = DefaultMainUseCase(repository: repository)
let vm = MainViewModel(mainUseCase: useCase)
let vc = MainViewController(viewModel: vm)
vc.viewModel = vm
return (vc, vm)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// MainCoordinator.swift
// MainFeatureInterface
//
// Created by 류희재 on 7/5/24.
// Copyright © 2024 Weather-iOS. All rights reserved.
//

import BaseFeatureDependency
import Core

public enum MainCoordinatorDestination {
case detail
}
public protocol MainCoordinatorOutput {
var requestCoordinating: ((MainCoordinatorDestination) -> Void)? { get set }
}
public typealias DefaultMainCoordinator = BaseCoordinator & MainCoordinatorOutput

public
final class MainCoordinator: DefaultMainCoordinator {

public var requestCoordinating: ((MainCoordinatorDestination) -> Void)?

private let factory: MainFeatureViewBuildable
private let router: Router

public init(router: Router, factory: MainFeatureViewBuildable) {
self.factory = factory
self.router = router
}

public override func start() {
var main = factory.makeMain()


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ import Then
import RxSwift
import RxGesture
import RxCocoa
import BaseFeatureDependency
import MainFeatureInterface

public final class MainViewController : UIViewController {

public final class MainViewController: UIViewController, MainViewControllable {
//MARK: - Properties

public let viewModel: MainViewModel
public var viewModel: MainViewModel
private let disposeBag = DisposeBag()

public let searchBarDidChangeSubject = PublishSubject<String>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ import Domain

import RxSwift
import RxCocoa
import MainFeatureInterface

public final class MainViewModel {
public final class MainViewModel: MainViewModelType {
internal var disposeBag = DisposeBag()

public let mainCoordinator: MainCoordinator?
public let mainUseCase: MainUseCase

public init(mainCoordinator: MainCoordinator? ,mainUseCase: MainUseCase) {
self.mainCoordinator = mainCoordinator
public init(mainUseCase: MainUseCase) {
self.mainUseCase = mainUseCase
}

Expand All @@ -34,7 +33,7 @@ public final class MainViewModel {
public var weatherList = BehaviorRelay<[CurrentWeatherModel]>(value: [])
}

func transform(from input: Input, disposeBag: DisposeBag) -> Output {
public func transform(from input: Input, disposeBag: DisposeBag) -> Output {
let output = Output()
self.bindOutput(output: output, disposeBag: disposeBag)

Expand All @@ -43,7 +42,7 @@ public final class MainViewModel {
}).disposed(by: disposeBag)

input.weatherListViewDidTapEvent.subscribe(with: self, onNext: { owner, page in
owner.mainCoordinator?.pushToDetailVC(with: page.item)
//owner.mainCoordinator?.pushToDetailVC(with: page.item)
}).disposed(by: disposeBag)

input.searchBarDidChangeEvent.subscribe(with: self, onNext: { owner, text in
Expand Down

0 comments on commit 13165d3

Please sign in to comment.