Skip to content

Commit

Permalink
🎨 AppCoordinator 내 extension 분리, 함수명 변경, 다중 pop 로직 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
yoondj98 committed Nov 30, 2023
1 parent 72e8be5 commit 9605250
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 74 deletions.
8 changes: 4 additions & 4 deletions iOS/MusicSpot/MusicSpot.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@
08CBF86F2B18468E007D3797 /* MSCoordinator */ = {
isa = PBXGroup;
children = (
08CBF8702B18468E007D3797 /* SaveJourneyCoordinator.swift */,
08CBF8772B18468E007D3797 /* Coordinator.swift */,
08CBF8712B18468E007D3797 /* AppCoordinator.swift */,
08CBF8722B18468E007D3797 /* RewindCoordinator.swift */,
08CBF8732B18468E007D3797 /* HomeMapCoordinator.swift */,
08CBF8742B18468E007D3797 /* SettingCoordinator.swift */,
08CBF8752B18468E007D3797 /* SpotCoordinator.swift */,
08CBF8722B18468E007D3797 /* RewindCoordinator.swift */,
08CBF8742B18468E007D3797 /* SettingCoordinator.swift */,
08CBF8762B18468E007D3797 /* SearchMusicCoordinator.swift */,
08CBF8772B18468E007D3797 /* Coordinator.swift */,
08CBF8702B18468E007D3797 /* SaveJourneyCoordinator.swift */,
);
path = MSCoordinator;
sourceTree = "<group>";
Expand Down
121 changes: 73 additions & 48 deletions iOS/MusicSpot/MusicSpot/MSCoordinator/AppCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@

import UIKit

final class AppCoordinator: Coordinator,
HomeMapCoordinatorDelegate,
SpotCoordinatorDelegate,
RewindCoordinatorDelegate,
SettingCoordinatorDelegate,
SearchMusicCoordinatorDelegate,
SaveJourneyCoordinatorDelegate {
final class AppCoordinator: Coordinator {

// MARK: - Properties

Expand All @@ -35,91 +29,122 @@ final class AppCoordinator: Coordinator,
self.childCoordinators.append(homeMapCoordinator)
homeMapCoordinator.start()
}
}

extension AppCoordinator {

/// 현재 ViewController 아래에 깔린 ViewController 내에서 HomeMapViewController를 찾는 함수
private func findHomeMapViewController() {
guard let homeMapViewController = navigationController.viewControllers.first(where: { $0 is HomeMapViewController }) else {
navigationController.setViewControllers([HomeMapViewController()], animated: true)
return
}

func navigateToSpot(coordinator: HomeMapCoordinator) {
navigationController.popToViewController(homeMapViewController, animated: true)
}
}

// MARK: - HomeMapCoordinatorDelegate

extension AppCoordinator: HomeMapCoordinatorDelegate {

/// From: HomeMap, To: Spot
func pushToSpot(coordinator: HomeMapCoordinator) {
let spotCoordinator = SpotCoordinator(navigationController: navigationController)
spotCoordinator.delegate = self

self.childCoordinators.append(spotCoordinator)
spotCoordinator.start()
}

func navigateToRewind(coordinator: HomeMapCoordinator) {
/// From: HomeMap, To: Rewind
func pushToRewind(coordinator: HomeMapCoordinator) {
let rewindCoordinator = RewindCoordinator(navigationController: navigationController)
rewindCoordinator.delegate = self

self.childCoordinators.append(rewindCoordinator)
rewindCoordinator.start()
}

func navigateToSetting(coordinator: HomeMapCoordinator) {
/// From: HomeMap, To: Setting
func pushToSetting(coordinator: HomeMapCoordinator) {
let settingCoordinator = SettingCoordinator(navigationController: navigationController)
settingCoordinator.delegate = self

self.childCoordinators.append(settingCoordinator)
settingCoordinator.start()
}
}

func navigateToHomeMap(coordinator: SpotCoordinator) {
removeChildCoordinator(child: coordinator)
navigationController.popViewController(animated: true)
}
// MARK: - SpotCoordinatorDelegate

func navigateToHomeMap(coordinator: RewindCoordinator) {
extension AppCoordinator: SpotCoordinatorDelegate {

/// From: Spot, To: HomeMap
func popToHomeMap(coordinator: SpotCoordinator) {
removeChildCoordinator(child: coordinator)
navigationController.popViewController(animated: true)
}

func navigateToHomeMap(coordinator: SettingCoordinator) {
navigationController.popViewController(animated: true)
}

// MARK: - From: Spot

func navigateToSearchMusic(coordinator: SpotCoordinator) {

/// From: Spot, To: SearchMusic
func pushToSearchMusic(coordinator: SpotCoordinator) {
let searchMusicCoordinator = SearchMusicCoordinator(navigationController: navigationController)
searchMusicCoordinator.delegate = self
self.childCoordinators.append(searchMusicCoordinator)
searchMusicCoordinator.start()
}
}

// MARK: - From: SearchMusic

func navigateToHomeMap(coordinator: SearchMusicCoordinator) {
guard let homeMapViewController = navigationController.viewControllers.first(where: {
$0 is HomeMapViewController
}) else {
navigationController.setViewControllers([HomeMapViewController()], animated: true)
return
}
// MARK: - SearchMusicCoordinatorDelegate

while navigationController.topViewController !== homeMapViewController {
navigationController.popViewController(animated: true)
}
extension AppCoordinator: SearchMusicCoordinatorDelegate {

/// From: SearchMusic, To: HomeMap
func popToHomeMap(coordinator: SearchMusicCoordinator) {
findHomeMapViewController()
}

func navigateToSaveJourney(coordinator: SearchMusicCoordinator) {
/// From: SearchMusic, To: SaveJourney
func pushToSaveJourney(coordinator: SearchMusicCoordinator) {
let saveJourneyCoordinator = SaveJourneyCoordinator(navigationController: navigationController)
saveJourneyCoordinator.delegate = self
self.childCoordinators.append(saveJourneyCoordinator)
saveJourneyCoordinator.start()
}
}

// MARK: - From: SaveJourney
func navigateToHomeMap(coordinator: SaveJourneyCoordinator) {
guard let homeMapViewController = navigationController.viewControllers.first(where: {
$0 is HomeMapViewController
}) else {
navigationController.setViewControllers([HomeMapViewController()], animated: true)
return
}
// MARK: - RewindCoordinatorDelegate

while navigationController.topViewController !== homeMapViewController {
navigationController.popViewController(animated: true)
}
extension AppCoordinator: RewindCoordinatorDelegate {

/// From: Rewind, To: HomeMap
func popToHomeMap(coordinator: RewindCoordinator) {
removeChildCoordinator(child: coordinator)
navigationController.popViewController(animated: true)
}
}

// MARK: - SettingCoordinatorDelegate

extension AppCoordinator: SettingCoordinatorDelegate {

/// From: Setting, To: HomeMap
func popToHomeMap(coordinator: SettingCoordinator) {
navigationController.popViewController(animated: true)
}
}

// MARK: - SaveJourneyCoordinatorDelegate

extension AppCoordinator: SaveJourneyCoordinatorDelegate {

/// From: SaveJourney, To: HomeMap
func popToHomeMap(coordinator: SaveJourneyCoordinator) {
findHomeMapViewController()
}

func navigateToSearchMusic(coordinator: SaveJourneyCoordinator) {
/// From: SaveJourney, To: SearchMusic
func popToSearchMusic(coordinator: SaveJourneyCoordinator) {
let searchMusicCoordinator = SearchMusicCoordinator(navigationController: navigationController)
searchMusicCoordinator.delegate = self
self.childCoordinators.append(searchMusicCoordinator)
Expand Down
12 changes: 6 additions & 6 deletions iOS/MusicSpot/MusicSpot/MSCoordinator/HomeMapCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import UIKit

protocol HomeMapCoordinatorDelegate: AnyObject {
func navigateToSpot(coordinator: HomeMapCoordinator)
func navigateToRewind(coordinator: HomeMapCoordinator)
func navigateToSetting(coordinator: HomeMapCoordinator)
func pushToSpot(coordinator: HomeMapCoordinator)
func pushToRewind(coordinator: HomeMapCoordinator)
func pushToSetting(coordinator: HomeMapCoordinator)
}

final class HomeMapCoordinator: Coordinator, HomeMapViewControllerDelegate {
Expand Down Expand Up @@ -38,14 +38,14 @@ final class HomeMapCoordinator: Coordinator, HomeMapViewControllerDelegate {
}

func goSpot() {
delegate?.navigateToSpot(coordinator: self)
delegate?.pushToSpot(coordinator: self)
}

func goRewind() {
delegate?.navigateToRewind(coordinator: self)
delegate?.pushToRewind(coordinator: self)
}

func goSetting() {
delegate?.navigateToSetting(coordinator: self)
delegate?.pushToSetting(coordinator: self)
}
}
4 changes: 2 additions & 2 deletions iOS/MusicSpot/MusicSpot/MSCoordinator/RewindCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import UIKit

protocol RewindCoordinatorDelegate: AnyObject {
func navigateToHomeMap(coordinator: RewindCoordinator)
func popToHomeMap(coordinator: RewindCoordinator)
}

final class RewindCoordinator: Coordinator, RewindViewControllerDelegate {
Expand Down Expand Up @@ -36,6 +36,6 @@ final class RewindCoordinator: Coordinator, RewindViewControllerDelegate {
}

func goHomeMap() {
delegate?.navigateToHomeMap(coordinator: self)
delegate?.popToHomeMap(coordinator: self)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import UIKit

protocol SaveJourneyCoordinatorDelegate: AnyObject {
func navigateToHomeMap(coordinator: SaveJourneyCoordinator)
func navigateToSearchMusic(coordinator: SaveJourneyCoordinator)
func popToHomeMap(coordinator: SaveJourneyCoordinator)
func popToSearchMusic(coordinator: SaveJourneyCoordinator)
}

final class SaveJourneyCoordinator: Coordinator, SaveJourneyViewControllerDelegate {
Expand Down Expand Up @@ -37,10 +37,10 @@ final class SaveJourneyCoordinator: Coordinator, SaveJourneyViewControllerDelega
}

func goHomeMap() {
delegate?.navigateToHomeMap(coordinator: self)
delegate?.popToHomeMap(coordinator: self)
}

func goSearchMusic() {
delegate?.navigateToSearchMusic(coordinator: self)
delegate?.popToSearchMusic(coordinator: self)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import UIKit

protocol SearchMusicCoordinatorDelegate: AnyObject {
func navigateToHomeMap(coordinator: SearchMusicCoordinator)
func navigateToSaveJourney(coordinator: SearchMusicCoordinator)
func popToHomeMap(coordinator: SearchMusicCoordinator)
func pushToSaveJourney(coordinator: SearchMusicCoordinator)
}

final class SearchMusicCoordinator: Coordinator, SearchMusicViewControllerDelegate {
Expand Down Expand Up @@ -37,10 +37,10 @@ final class SearchMusicCoordinator: Coordinator, SearchMusicViewControllerDelega
}

func goHomeMap() {
delegate?.navigateToHomeMap(coordinator: self)
delegate?.popToHomeMap(coordinator: self)
}

func goSaveJourney() {
delegate?.navigateToSaveJourney(coordinator: self)
delegate?.pushToSaveJourney(coordinator: self)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import UIKit

protocol SettingCoordinatorDelegate: AnyObject {
func navigateToHomeMap(coordinator: SettingCoordinator)
func popToHomeMap(coordinator: SettingCoordinator)
}

final class SettingCoordinator: Coordinator, SettingViewControllerDelegate {
Expand Down Expand Up @@ -36,6 +36,6 @@ final class SettingCoordinator: Coordinator, SettingViewControllerDelegate {
}

func goHomeMap() {
delegate?.navigateToHomeMap(coordinator: self)
delegate?.popToHomeMap(coordinator: self)
}
}
8 changes: 4 additions & 4 deletions iOS/MusicSpot/MusicSpot/MSCoordinator/SpotCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import UIKit

protocol SpotCoordinatorDelegate: AnyObject {
func navigateToHomeMap(coordinator: SpotCoordinator)
func navigateToSearchMusic(coordinator: SpotCoordinator)
func popToHomeMap(coordinator: SpotCoordinator)
func pushToSearchMusic(coordinator: SpotCoordinator)
}

final class SpotCoordinator: Coordinator, SpotViewControllerDelegate {
Expand All @@ -36,10 +36,10 @@ final class SpotCoordinator: Coordinator, SpotViewControllerDelegate {
}

func goHomeMap() {
delegate?.navigateToHomeMap(coordinator: self)
delegate?.popToHomeMap(coordinator: self)
}

func goSearchMusic() {
delegate?.navigateToSearchMusic(coordinator: self)
delegate?.pushToSearchMusic(coordinator: self)
}
}

0 comments on commit 9605250

Please sign in to comment.