Skip to content

Commit

Permalink
Refactor: Child Coordinator 추가
Browse files Browse the repository at this point in the history
- 각 Coordinator의 childCoordinator 프로퍼티의 역할이 모호한 것 같아 제거하였으나
coordinaotor에서 동작해야하는 메서드들이 동작하지 않는 것을 확인
AppCoordinator에 해당하는 Coordinator를 선언 후 어느곳에도 갖고 있지 않아 nil이 되어 present가 되지 않음
따라서 ChildCoordinator를 다시 추가하였음
-> 느낌으로는 이해했지만 ChildCoordinator를 재확인해봐야할것같음
  • Loading branch information
iOS-Ruel committed Aug 7, 2024
1 parent 7957011 commit 8f8f27e
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 12 deletions.
4 changes: 3 additions & 1 deletion CamPlace/CamPlace/Coordinator/AppCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class AppCoordinator: Coordinator {

let firstViewCoordinator = MainMapViewCoordinator()
firstViewCoordinator.parentCoordinator = self

childCoordinator.append(firstViewCoordinator)

firstViewCoordinator.start()

let mainMapVC = firstViewCoordinator.navigationController
Expand All @@ -40,6 +41,7 @@ class AppCoordinator: Coordinator {

let secondViewCoordinator = LocationFavoriteCoordinator()
secondViewCoordinator.parentCoordinator = self
childCoordinator.append(secondViewCoordinator)


secondViewCoordinator.start()
Expand Down
2 changes: 2 additions & 0 deletions CamPlace/CamPlace/Coordinator/Coordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ import Foundation

protocol Coordinator: AnyObject {
func start()
var childCoordinator: [Coordinator] { get set }

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import UIKit
class PlaceDetailViewCoordinator: Coordinator {
var navigationController: UINavigationController
weak var parentCoordinator: Coordinator?
var childCoordinator: [Coordinator] = []

var viewModel: PlaceDetailViewModel

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ import UIKit
class LocationFavoriteCoordinator: Coordinator {
var navigationController: UINavigationController
weak var parentCoordinator: Coordinator?



var childCoordinator: [Coordinator] = []

init(){
self.navigationController = .init()
}
Expand All @@ -32,8 +31,8 @@ extension LocationFavoriteCoordinator: LocationFavoriteDelegate {
let detailViewModel = PlaceDetailViewModel(content: content)
let detailCoordinator = PlaceDetailViewCoordinator(navigationController: navigationController, viewModel: detailViewModel)
detailCoordinator.parentCoordinator = self

childCoordinator.append(detailCoordinator)

detailCoordinator.start()

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ protocol LocationFavoriteDelegate: AnyObject {
}

class LocationFavoriteViewModel: PlaceListProtocol {

private var cancellables: Set<AnyCancellable> = []

@Published var locations: [Location] = []
Expand All @@ -31,7 +31,7 @@ class LocationFavoriteViewModel: PlaceListProtocol {
}
.store(in: &cancellables)
}


func doFavoriteModel(locationContent: LocationBasedListModel) -> AnyPublisher<Bool, Never>? {
Future<Bool, Never> { promise in
Expand All @@ -53,7 +53,7 @@ class LocationFavoriteViewModel: PlaceListProtocol {
func locationListCount() -> Int {
return locations.count
}


func isFavorite(content: LocationBasedListModel) -> AnyPublisher<Bool, Never>? {
Future<Bool, Never> { promise in
Expand Down
11 changes: 9 additions & 2 deletions CamPlace/CamPlace/Main/MainMap/MainMapViewCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ protocol MainMapDelegate: AnyObject {
class MainMapViewCoordinator: Coordinator {
var navigationController: UINavigationController
weak var parentCoordinator: Coordinator?

var childCoordinator: [Coordinator] = []

init(){
self.navigationController = .init()

}

func start() {
Expand All @@ -34,17 +34,24 @@ class MainMapViewCoordinator: Coordinator {

extension MainMapViewCoordinator: MainMapDelegate {
func pushDetialVC(content: LocationBasedListModel) {
print("pushdetail")
let detailViewModel = PlaceDetailViewModel(content: content)
let detailCoordinator = PlaceDetailViewCoordinator(navigationController: navigationController, viewModel: detailViewModel)
detailCoordinator.parentCoordinator = self
childCoordinator.append(detailCoordinator)

detailCoordinator.start()

}

func presentLocationList(contents: [LocationBasedListModel]) {
print("present")
let listViewModel = PlaceListViewModel(locationList: contents)
let placeListCoordinator = PlaceListViewCoordinator(navigationController: navigationController, viewModel: listViewModel)
placeListCoordinator.parentCoordinator = self
childCoordinator.append(placeListCoordinator)

placeListCoordinator.start()

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class PlaceListViewCoordinator: Coordinator {
var navigationController: UINavigationController
weak var parentCoordinator: Coordinator?
var viewModel: PlaceListViewModel

var childCoordinator: [Coordinator] = []

init(navigationController: UINavigationController, viewModel: PlaceListViewModel) {
self.navigationController = navigationController
self.viewModel = viewModel
Expand Down Expand Up @@ -46,6 +47,8 @@ extension PlaceListViewCoordinator {
let viewModel = PlaceDetailViewModel(content: content)
let detailCoordinator = PlaceDetailViewCoordinator(navigationController: navigationController, viewModel: viewModel)
detailCoordinator.parentCoordinator = self
childCoordinator.append(detailCoordinator)

detailCoordinator.startPresent()
}
}

0 comments on commit 8f8f27e

Please sign in to comment.