Skip to content

Commit ee1482b

Browse files
authored
[NL-7]: 앱 초기 실행 플로우 구현 (#40)
1 parent abf4131 commit ee1482b

23 files changed

+249
-123
lines changed

App/Sources/AppDelegate+Assembly.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,17 @@ import Foundation
1212
import Lib
1313
import NetworkCore
1414
import Setting
15+
import Onboarding
1516

1617
extension AppDelegate {
17-
func dependencyInjection() {
18+
func setupDependencyInjector() {
1819
DependencyInjector.shared.assemble([
1920
SettingAssembly(),
2021
AuthAssembly(),
2122
NetworkCoreAssembly(),
2223
LibAssembly(),
2324
FortuneAssembly(),
25+
OnboardingAssembly()
2426
])
2527
}
2628
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// AppDelegate+DependencyHandler.swift
3+
// Satto
4+
//
5+
// Created by ttozzi on 8/16/25.
6+
//
7+
8+
import Foundation
9+
import Lib
10+
11+
extension AppDelegate {
12+
func setupDependencyHandler() {
13+
DependencyHandler.shared.register(dependencies: [
14+
AppDependencyHandler()
15+
])
16+
}
17+
}

App/Sources/AppDelegate.swift

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1212
_ application: UIApplication,
1313
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
1414
) -> Bool {
15-
dependencyInjection()
16-
registRouter()
15+
setupDependencyInjector()
16+
setupDependencyHandler()
1717
return true
1818
}
1919

@@ -35,10 +35,4 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
3535
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
3636
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
3737
}
38-
39-
private func registRouter() {
40-
let appRouter = AppRouter.shared
41-
42-
appRouter.register(route: .onboarding(onboardingRoute: nil), factory: { OnboardingRouter() })
43-
}
4438
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//
2+
// AppDependencyHandler.swift
3+
// Satto
4+
//
5+
// Created by ttozzi on 8/16/25.
6+
//
7+
8+
import Base
9+
import Foundation
10+
import Lib
11+
import Home
12+
import Fortune
13+
import Setting
14+
import UIKit
15+
16+
struct AppDependencyHandler: DependencyRegistrable {
17+
func register(to dependencyHandler: DependencyHandler) {
18+
dependencyHandler.register(key: DependencyKey.App.configureTabBarController) {
19+
Task { @MainActor in
20+
self.configureTabBarController()
21+
}
22+
}
23+
}
24+
25+
private func configureTabBarController() {
26+
// TODO: 이미 TabBarController 가 있는 경우에 대한 예외 처리
27+
let tabBarController = BaseTabBarController()
28+
tabBarController.viewControllers = [
29+
HomeViewController(viewModel: HomeViewModel()),
30+
FortuneViewController(viewModel: FortuneViewModel()),
31+
UIViewController(), // TODO: 뭐 나왔지
32+
MyPageViewController(viewModel: MyPageViewModel())
33+
]
34+
UIApplication.shared.activeWindow?.rootViewController = tabBarController
35+
}
36+
}
37+
38+
private extension UIApplication {
39+
var activeWindow: UIWindow? {
40+
return connectedScenes
41+
.compactMap { $0 as? UIWindowScene }
42+
.flatMap { $0.windows }
43+
.first { $0.isKeyWindow }
44+
}
45+
}

App/Sources/SceneDelegate.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Onboarding
22
import UIKit
3+
import Lib
34

45
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
56

@@ -13,7 +14,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
1314
window = UIWindow(windowScene: windowScene)
1415
window?.windowScene = windowScene
1516

16-
let viewController = LaunchScreenViewController()
17+
let viewController = LaunchScreenViewController(viewModel: LaunchScreenViewModel())
1718

1819
window?.rootViewController = viewController
1920
window?.makeKeyAndVisible()

Common/Base/Sources/BaseViewController.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// Created by ttozzi on 8/10/25.
66
//
77

8+
import Combine
89
import SnapKit
910
import UIKit
1011

@@ -22,6 +23,7 @@ open class BaseViewController: UIViewController {
2223
set { navigationBar.title = newValue }
2324
}
2425
private var navigationAreaHeight: Constraint?
26+
public var cancellables = Set<AnyCancellable>()
2527

2628
open override func viewDidLoad() {
2729
super.viewDidLoad()

Common/Base/Sources/TabBar/BaseTabBarController.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@ import SnapKit
1111
import Then
1212
import UIKit
1313

14-
final class BaseTabBarController: UITabBarController {
14+
public final class BaseTabBarController: UITabBarController {
1515

1616
private lazy var customTabBar = TabBarView().then {
1717
$0.backgroundColor = STColors.white.color
1818
}
1919
private var cancellables = Set<AnyCancellable>()
2020

21-
override func viewDidLoad() {
21+
public override func viewDidLoad() {
2222
super.viewDidLoad()
2323
setupTabBar()
2424
setupBindings()
2525
}
2626

27-
override func viewDidLayoutSubviews() {
27+
public override func viewDidLayoutSubviews() {
2828
super.viewDidLayoutSubviews()
2929

3030
if let window = view.window {

Common/Lib/Sources/LibAssembly.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import Foundation
1010

1111
public final class LibAssembly: Assembly {
1212
public func assemble(container: Container) {
13-
container.register(AppRouter.self) { _ in
14-
return AppRouter.shared
13+
container.register(DependencyHandler.self) { _ in
14+
return DependencyHandler.shared
1515
}
1616
}
1717

Common/Lib/Sources/Router/AppRouter.swift

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -8,81 +8,12 @@
88
import Foundation
99
import UIKit
1010

11-
public enum AppRoute: Hashable {
12-
case fortune
13-
case history
14-
case home
15-
case onboarding(onboardingRoute: OnboardingRoute?)
16-
case setting
17-
18-
public func hash(into hasher: inout Hasher) {
19-
switch self {
20-
case .fortune:
21-
hasher.combine(0)
22-
case .history:
23-
hasher.combine(1)
24-
case .home:
25-
hasher.combine(2)
26-
case .onboarding(let onboardingRoute):
27-
hasher.combine(3)
28-
case .setting:
29-
hasher.combine(4)
30-
}
31-
}
32-
33-
public static func == (lhs: AppRoute, rhs: AppRoute) -> Bool {
34-
switch (lhs, rhs) {
35-
case (.fortune, .fortune), (.history, .history), (.home, .home), (.setting, .setting):
36-
return true
37-
case (.onboarding, .onboarding):
38-
return true
39-
default:
40-
return false
41-
}
42-
}
43-
}
44-
4511
@MainActor
4612
public protocol Routable: AnyObject {
4713
func navigate(to route: Any, how: NavigateType, with data: [String: Any])
4814
func setFactories()
4915
}
5016

51-
public final class AppRouter: Routable {
52-
public static let shared = AppRouter()
53-
54-
private var factories: [AppRoute: () -> Routable] = [:]
55-
56-
private init() {}
57-
58-
public func register(route: AppRoute, factory: @escaping () -> Routable) {
59-
factories[route] = factory
60-
}
61-
62-
public func navigate(to route: Any, how: NavigateType, with data: [String: Any]) {
63-
guard let appRoute = route as? AppRoute else { return }
64-
guard let factory = factories[appRoute] else { return }
65-
let subRouter = factory()
66-
67-
switch appRoute {
68-
case .fortune:
69-
break
70-
case .history:
71-
break
72-
case .home:
73-
break
74-
case .onboarding(let onboardingRoute):
75-
guard let onboardingRoute = onboardingRoute else { return }
76-
77-
subRouter.navigate(to: onboardingRoute, how: how, with: data)
78-
case .setting:
79-
break
80-
}
81-
}
82-
83-
public func setFactories() {}
84-
}
85-
8617
extension Routable {
8718
public func topViewController(
8819
from base: UIViewController? = UIApplication.shared.connectedScenes
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//
2+
// DependencyHandler.swift
3+
// Lib
4+
//
5+
// Created by ttozzi on 8/16/25.
6+
//
7+
8+
import Foundation
9+
10+
public final class DependencyHandler {
11+
12+
public static let shared = DependencyHandler()
13+
14+
private var handlers: [String: () -> Void] = [:]
15+
16+
private init() {}
17+
18+
public func register(dependencies: [any DependencyRegistrable]) {
19+
dependencies.forEach {
20+
$0.register(to: self)
21+
}
22+
}
23+
24+
public func register(key: String, handler: @escaping () -> Void) {
25+
handlers[key] = handler
26+
}
27+
28+
public func handle(key: String) {
29+
handlers[key]?()
30+
}
31+
}
32+
33+
public protocol DependencyRegistrable {
34+
func register(to dependencyHandler: DependencyHandler)
35+
}

0 commit comments

Comments
 (0)