From 0fd347ed66e55667e4cbb09ddd276774e896adeb Mon Sep 17 00:00:00 2001 From: Mori Atsushi Date: Mon, 21 May 2018 00:15:09 +0900 Subject: [PATCH 1/3] =?UTF-8?q?[add]=20DI=20Container=E3=81=AE=E9=9B=9B?= =?UTF-8?q?=E5=BD=A2=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SyncPod.xcodeproj/project.pbxproj | 20 ++++++++++++++++++++ SyncPod/AppDelegate.swift | 15 +++++++++++---- SyncPod/di/CoordinatorAssembly.swift | 24 ++++++++++++++++++++++++ SyncPod/di/ViewControllerAssembly.swift | 17 +++++++++++++++++ SyncPod/di/ViewModelAssembly.swift | 17 +++++++++++++++++ 5 files changed, 89 insertions(+), 4 deletions(-) create mode 100644 SyncPod/di/CoordinatorAssembly.swift create mode 100644 SyncPod/di/ViewControllerAssembly.swift create mode 100644 SyncPod/di/ViewModelAssembly.swift diff --git a/SyncPod.xcodeproj/project.pbxproj b/SyncPod.xcodeproj/project.pbxproj index 8be50d6..1e6adf3 100644 --- a/SyncPod.xcodeproj/project.pbxproj +++ b/SyncPod.xcodeproj/project.pbxproj @@ -22,6 +22,9 @@ 0D7FC6A020B172A400CB4169 /* ApplicationCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D7FC69F20B172A400CB4169 /* ApplicationCoordinator.swift */; }; 0D7FC6A320B1949D00CB4169 /* WelcomeCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D7FC6A220B1949D00CB4169 /* WelcomeCoordinator.swift */; }; 0D7FC6A520B1966300CB4169 /* BaseCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D7FC6A420B1966300CB4169 /* BaseCoordinator.swift */; }; + 0D7FC6AA20B1C18200CB4169 /* ViewControllerAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D7FC6A920B1C18200CB4169 /* ViewControllerAssembly.swift */; }; + 0D7FC6AC20B1C35B00CB4169 /* ViewModelAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D7FC6AB20B1C35B00CB4169 /* ViewModelAssembly.swift */; }; + 0D7FC6B020B1C6F300CB4169 /* CoordinatorAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D7FC6AF20B1C6F300CB4169 /* CoordinatorAssembly.swift */; }; 0D8BB2B62010A25700C7F6A9 /* ActionCableClient.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0D8BB2B52010A25700C7F6A9 /* ActionCableClient.framework */; }; 0D8BB2B82010A37900C7F6A9 /* Starscream.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0D8BB2B72010A37900C7F6A9 /* Starscream.framework */; }; 0DE94BFD201289A700E26582 /* YouTubePlayer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0DE94BFC201289A700E26582 /* YouTubePlayer.framework */; }; @@ -73,6 +76,9 @@ 0D7FC69F20B172A400CB4169 /* ApplicationCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApplicationCoordinator.swift; sourceTree = ""; }; 0D7FC6A220B1949D00CB4169 /* WelcomeCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WelcomeCoordinator.swift; sourceTree = ""; }; 0D7FC6A420B1966300CB4169 /* BaseCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseCoordinator.swift; sourceTree = ""; }; + 0D7FC6A920B1C18200CB4169 /* ViewControllerAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewControllerAssembly.swift; sourceTree = ""; }; + 0D7FC6AB20B1C35B00CB4169 /* ViewModelAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewModelAssembly.swift; sourceTree = ""; }; + 0D7FC6AF20B1C6F300CB4169 /* CoordinatorAssembly.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoordinatorAssembly.swift; sourceTree = ""; }; 0D8BB2B52010A25700C7F6A9 /* ActionCableClient.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ActionCableClient.framework; path = Carthage/Build/iOS/ActionCableClient.framework; sourceTree = ""; }; 0D8BB2B72010A37900C7F6A9 /* Starscream.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Starscream.framework; path = Carthage/Build/iOS/Starscream.framework; sourceTree = ""; }; 0DE94BFA2012899600E26582 /* YouTubePlayer.framework.dSYM */ = {isa = PBXFileReference; lastKnownFileType = wrapper.dsym; name = YouTubePlayer.framework.dSYM; path = Carthage/Build/iOS/YouTubePlayer.framework.dSYM; sourceTree = ""; }; @@ -171,6 +177,7 @@ 0D5B826E1FC9A5D30055A72C /* SyncPod */ = { isa = PBXGroup; children = ( + 0D7FC6A620B1BD9200CB4169 /* di */, 0D7FC6A120B1945400CB4169 /* coordinator */, 0D7FC69B20B164BF00CB4169 /* viewmodel */, 0DFF805320B155CB0087411D /* view */, @@ -219,6 +226,16 @@ path = coordinator; sourceTree = ""; }; + 0D7FC6A620B1BD9200CB4169 /* di */ = { + isa = PBXGroup; + children = ( + 0D7FC6A920B1C18200CB4169 /* ViewControllerAssembly.swift */, + 0D7FC6AB20B1C35B00CB4169 /* ViewModelAssembly.swift */, + 0D7FC6AF20B1C6F300CB4169 /* CoordinatorAssembly.swift */, + ); + path = di; + sourceTree = ""; + }; 0DFF805020B155890087411D /* storyboard */ = { isa = PBXGroup; children = ( @@ -411,9 +428,12 @@ files = ( 0D5B82701FC9A5D30055A72C /* AppDelegate.swift in Sources */, 0D7FC6A520B1966300CB4169 /* BaseCoordinator.swift in Sources */, + 0D7FC6B020B1C6F300CB4169 /* CoordinatorAssembly.swift in Sources */, + 0D7FC6AC20B1C35B00CB4169 /* ViewModelAssembly.swift in Sources */, 0D7FC69D20B164D100CB4169 /* WelcomeViewModel.swift in Sources */, 0D7FC6A320B1949D00CB4169 /* WelcomeCoordinator.swift in Sources */, 0D7FC69A20B1636700CB4169 /* WelcomeViewController.swift in Sources */, + 0D7FC6AA20B1C18200CB4169 /* ViewControllerAssembly.swift in Sources */, 0D7FC6A020B172A400CB4169 /* ApplicationCoordinator.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/SyncPod/AppDelegate.swift b/SyncPod/AppDelegate.swift index acb8bb3..bb0751d 100644 --- a/SyncPod/AppDelegate.swift +++ b/SyncPod/AppDelegate.swift @@ -7,26 +7,33 @@ // import UIKit +import Swinject @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - lazy var applicationCoordinator = ApplicationCoordinator(window: self.window!) + lazy var assembler = Assembler([ + CoordinatorAssembly(), + ViewModelAssembly(), + ViewControllerAssembly() + ]) + lazy var coordinator = assembler.resolver.resolve(ApplicationCoordinator.self)! func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]? ) -> Bool { - applicationCoordinator.start() + coordinator.start() return true } func application( - _ application: UIApplication, open url: URL, + _ application: UIApplication, + open url: URL, options: [UIApplicationOpenURLOptionsKey: Any] = [:] ) -> Bool { - applicationCoordinator.start() + coordinator.start() return true } diff --git a/SyncPod/di/CoordinatorAssembly.swift b/SyncPod/di/CoordinatorAssembly.swift new file mode 100644 index 0000000..fb5db25 --- /dev/null +++ b/SyncPod/di/CoordinatorAssembly.swift @@ -0,0 +1,24 @@ +// +// CoordinatorAssembly.swift +// SyncPod +// +// Created by 森篤史 on 2018/05/20. +// Copyright © 2018年 Cyder. All rights reserved. +// + +import UIKit +import Swinject + +class CoordinatorAssembly: Assembly { + weak var delegate = UIApplication.shared.delegate as? AppDelegate + + func assemble(container: Container) { + container.register(ApplicationCoordinator.self) { _ in + return ApplicationCoordinator(window: (self.delegate?.window)!) + }.inObjectScope(.container) + + container.register(WelcomeCoordinator.self) { _ in + return WelcomeCoordinator(window: (self.delegate?.window)!) + }.inObjectScope(.container) + } +} diff --git a/SyncPod/di/ViewControllerAssembly.swift b/SyncPod/di/ViewControllerAssembly.swift new file mode 100644 index 0000000..5a0b98f --- /dev/null +++ b/SyncPod/di/ViewControllerAssembly.swift @@ -0,0 +1,17 @@ +// +// ViewControllerAssembly.swift +// SyncPod +// +// Created by 森篤史 on 2018/05/20. +// Copyright © 2018年 Cyder. All rights reserved. +// + +import Swinject + +class ViewControllerAssembly: Assembly { + func assemble(container: Container) { + container.register(WelcomeViewConstoller.self) { _ in + return WelcomeViewConstoller() + } + } +} diff --git a/SyncPod/di/ViewModelAssembly.swift b/SyncPod/di/ViewModelAssembly.swift new file mode 100644 index 0000000..b27afeb --- /dev/null +++ b/SyncPod/di/ViewModelAssembly.swift @@ -0,0 +1,17 @@ +// +// ViewModelAssembly.swift +// SyncPod +// +// Created by 森篤史 on 2018/05/20. +// Copyright © 2018年 Cyder. All rights reserved. +// + +import Swinject + +class ViewModelAssembly: Assembly { + func assemble(container: Container) { + container.register(WelcomeViewModel.self) { _ in + return WelcomeViewModel() + }.inObjectScope(.container) + } +} From 3d1fe3aa9973480f9cf97137cbda4a9ee081b0c9 Mon Sep 17 00:00:00 2001 From: Mori Atsushi Date: Mon, 21 May 2018 16:12:36 +0900 Subject: [PATCH 2/3] =?UTF-8?q?[wip]=20DI=E3=81=AE=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SyncPod.xcodeproj/project.pbxproj | 8 +++++-- SyncPod/AppDelegate.swift | 8 ++----- .../coordinator/ApplicationCoordinator.swift | 6 ++--- SyncPod/coordinator/WelcomeCoordinator.swift | 16 +++++--------- SyncPod/di/CoordinatorAssembly.swift | 10 ++++----- SyncPod/di/DependencyManager.swift | 22 +++++++++++++++++++ SyncPod/di/ViewControllerAssembly.swift | 5 +++-- SyncPod/di/ViewModelAssembly.swift | 6 +++-- .../WelcomeViewController.swift | 8 ++++--- SyncPod/viewmodel/WelcomeViewModel.swift | 9 +++++--- 10 files changed, 61 insertions(+), 37 deletions(-) create mode 100644 SyncPod/di/DependencyManager.swift diff --git a/SyncPod.xcodeproj/project.pbxproj b/SyncPod.xcodeproj/project.pbxproj index 1e6adf3..2e1c7ac 100644 --- a/SyncPod.xcodeproj/project.pbxproj +++ b/SyncPod.xcodeproj/project.pbxproj @@ -25,6 +25,7 @@ 0D7FC6AA20B1C18200CB4169 /* ViewControllerAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D7FC6A920B1C18200CB4169 /* ViewControllerAssembly.swift */; }; 0D7FC6AC20B1C35B00CB4169 /* ViewModelAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D7FC6AB20B1C35B00CB4169 /* ViewModelAssembly.swift */; }; 0D7FC6B020B1C6F300CB4169 /* CoordinatorAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D7FC6AF20B1C6F300CB4169 /* CoordinatorAssembly.swift */; }; + 0D7FC6B220B1C9DF00CB4169 /* DependencyManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D7FC6B120B1C9DF00CB4169 /* DependencyManager.swift */; }; 0D8BB2B62010A25700C7F6A9 /* ActionCableClient.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0D8BB2B52010A25700C7F6A9 /* ActionCableClient.framework */; }; 0D8BB2B82010A37900C7F6A9 /* Starscream.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0D8BB2B72010A37900C7F6A9 /* Starscream.framework */; }; 0DE94BFD201289A700E26582 /* YouTubePlayer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0DE94BFC201289A700E26582 /* YouTubePlayer.framework */; }; @@ -79,6 +80,7 @@ 0D7FC6A920B1C18200CB4169 /* ViewControllerAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewControllerAssembly.swift; sourceTree = ""; }; 0D7FC6AB20B1C35B00CB4169 /* ViewModelAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewModelAssembly.swift; sourceTree = ""; }; 0D7FC6AF20B1C6F300CB4169 /* CoordinatorAssembly.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoordinatorAssembly.swift; sourceTree = ""; }; + 0D7FC6B120B1C9DF00CB4169 /* DependencyManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DependencyManager.swift; sourceTree = ""; }; 0D8BB2B52010A25700C7F6A9 /* ActionCableClient.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ActionCableClient.framework; path = Carthage/Build/iOS/ActionCableClient.framework; sourceTree = ""; }; 0D8BB2B72010A37900C7F6A9 /* Starscream.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Starscream.framework; path = Carthage/Build/iOS/Starscream.framework; sourceTree = ""; }; 0DE94BFA2012899600E26582 /* YouTubePlayer.framework.dSYM */ = {isa = PBXFileReference; lastKnownFileType = wrapper.dsym; name = YouTubePlayer.framework.dSYM; path = Carthage/Build/iOS/YouTubePlayer.framework.dSYM; sourceTree = ""; }; @@ -98,7 +100,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 0D86F07520B2AA8E00FA68C7 /* SwinjectStoryboard.framework in Frameworks */, + 0D7FC6B420B1DDA100CB4169 /* SwinjectStoryboard.framework in Frameworks */, 0DFF805820B157550087411D /* RxCocoa.framework in Frameworks */, 0DF11A0220A46E5C00D04895 /* Swinject.framework in Frameworks */, 0DF11A0020A46DDB00D04895 /* RxAlamofire.framework in Frameworks */, @@ -134,7 +136,7 @@ 0D4B438220099E540035DF1D /* Frameworks */ = { isa = PBXGroup; children = ( - 0D86F07420B2AA8E00FA68C7 /* SwinjectStoryboard.framework */, + 0D7FC6B320B1DDA100CB4169 /* SwinjectStoryboard.framework */, 0DFF805720B157550087411D /* RxCocoa.framework */, 0DFF805520B1573F0087411D /* RxCocoa.framework.dSYM */, 0DF11A0120A46E5C00D04895 /* Swinject.framework */, @@ -232,6 +234,7 @@ 0D7FC6A920B1C18200CB4169 /* ViewControllerAssembly.swift */, 0D7FC6AB20B1C35B00CB4169 /* ViewModelAssembly.swift */, 0D7FC6AF20B1C6F300CB4169 /* CoordinatorAssembly.swift */, + 0D7FC6B120B1C9DF00CB4169 /* DependencyManager.swift */, ); path = di; sourceTree = ""; @@ -428,6 +431,7 @@ files = ( 0D5B82701FC9A5D30055A72C /* AppDelegate.swift in Sources */, 0D7FC6A520B1966300CB4169 /* BaseCoordinator.swift in Sources */, + 0D7FC6B220B1C9DF00CB4169 /* DependencyManager.swift in Sources */, 0D7FC6B020B1C6F300CB4169 /* CoordinatorAssembly.swift in Sources */, 0D7FC6AC20B1C35B00CB4169 /* ViewModelAssembly.swift in Sources */, 0D7FC69D20B164D100CB4169 /* WelcomeViewModel.swift in Sources */, diff --git a/SyncPod/AppDelegate.swift b/SyncPod/AppDelegate.swift index bb0751d..1ad2679 100644 --- a/SyncPod/AppDelegate.swift +++ b/SyncPod/AppDelegate.swift @@ -8,17 +8,13 @@ import UIKit import Swinject +import SwinjectStoryboard @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - lazy var assembler = Assembler([ - CoordinatorAssembly(), - ViewModelAssembly(), - ViewControllerAssembly() - ]) - lazy var coordinator = assembler.resolver.resolve(ApplicationCoordinator.self)! + lazy var coordinator = DependencyManager.getResolver().resolve(ApplicationCoordinator.self)! func application( _ application: UIApplication, diff --git a/SyncPod/coordinator/ApplicationCoordinator.swift b/SyncPod/coordinator/ApplicationCoordinator.swift index 8d93810..001f93e 100644 --- a/SyncPod/coordinator/ApplicationCoordinator.swift +++ b/SyncPod/coordinator/ApplicationCoordinator.swift @@ -9,12 +9,10 @@ import UIKit class ApplicationCoordinator: BaseCoordinator { - private let window: UIWindow private let welcomeCoordinator: WelcomeCoordinator - init(window: UIWindow) { - self.window = window - self.welcomeCoordinator = WelcomeCoordinator(window: window) + init(welcomeCoordinator: WelcomeCoordinator) { + self.welcomeCoordinator = welcomeCoordinator } func start() { diff --git a/SyncPod/coordinator/WelcomeCoordinator.swift b/SyncPod/coordinator/WelcomeCoordinator.swift index 85bd34d..15de3cc 100644 --- a/SyncPod/coordinator/WelcomeCoordinator.swift +++ b/SyncPod/coordinator/WelcomeCoordinator.swift @@ -7,25 +7,21 @@ // import UIKit +import SwinjectStoryboard class WelcomeCoordinator: BaseCoordinator { + weak var delegate = UIApplication.shared.delegate as? AppDelegate private let window: UIWindow - private let storyboard: UIStoryboard + private let storyboard: SwinjectStoryboard private var nowViewController: UIViewController - init(window: UIWindow) { - self.window = window - self.storyboard = UIStoryboard(name: "Welcome", bundle: nil) + init() { + self.window = (delegate?.window)! + self.storyboard = SwinjectStoryboard.create(name: "Welcome", bundle: nil) self.nowViewController = storyboard.instantiateViewController(withIdentifier: "WelcomeView") - if let welcomeVC = nowViewController as? WelcomeViewConstoller { - let viewModel = WelcomeViewModel() - viewModel.coordinator = self - welcomeVC.viewModel = viewModel - } } func start() { - window.rootViewController = nowViewController } func navigateToSignIn() { diff --git a/SyncPod/di/CoordinatorAssembly.swift b/SyncPod/di/CoordinatorAssembly.swift index fb5db25..f7f6eac 100644 --- a/SyncPod/di/CoordinatorAssembly.swift +++ b/SyncPod/di/CoordinatorAssembly.swift @@ -10,15 +10,15 @@ import UIKit import Swinject class CoordinatorAssembly: Assembly { - weak var delegate = UIApplication.shared.delegate as? AppDelegate - func assemble(container: Container) { - container.register(ApplicationCoordinator.self) { _ in - return ApplicationCoordinator(window: (self.delegate?.window)!) + container.register(ApplicationCoordinator.self) { res in + ApplicationCoordinator( + welcomeCoordinator: res.resolve(WelcomeCoordinator.self)! + ) }.inObjectScope(.container) container.register(WelcomeCoordinator.self) { _ in - return WelcomeCoordinator(window: (self.delegate?.window)!) + WelcomeCoordinator() }.inObjectScope(.container) } } diff --git a/SyncPod/di/DependencyManager.swift b/SyncPod/di/DependencyManager.swift new file mode 100644 index 0000000..cd74e7a --- /dev/null +++ b/SyncPod/di/DependencyManager.swift @@ -0,0 +1,22 @@ +// +// DependencyManager.swift +// SyncPod +// +// Created by 森篤史 on 2018/05/21. +// Copyright © 2018年 Cyder. All rights reserved. +// + +import Swinject +import SwinjectStoryboard + +class DependencyManager { + static let assembler = Assembler([ + CoordinatorAssembly(), + ViewModelAssembly(), + ViewControllerAssembly() + ], container: SwinjectStoryboard.defaultContainer) + + static func getResolver() -> Resolver { + return assembler.resolver + } +} diff --git a/SyncPod/di/ViewControllerAssembly.swift b/SyncPod/di/ViewControllerAssembly.swift index 5a0b98f..c318dfa 100644 --- a/SyncPod/di/ViewControllerAssembly.swift +++ b/SyncPod/di/ViewControllerAssembly.swift @@ -7,11 +7,12 @@ // import Swinject +import SwinjectStoryboard class ViewControllerAssembly: Assembly { func assemble(container: Container) { - container.register(WelcomeViewConstoller.self) { _ in - return WelcomeViewConstoller() + container.storyboardInitCompleted(WelcomeViewConstoller.self) { res, viewController in + viewController.viewModel = res.resolve(WelcomeViewModel.self)! } } } diff --git a/SyncPod/di/ViewModelAssembly.swift b/SyncPod/di/ViewModelAssembly.swift index b27afeb..ba927ae 100644 --- a/SyncPod/di/ViewModelAssembly.swift +++ b/SyncPod/di/ViewModelAssembly.swift @@ -10,8 +10,10 @@ import Swinject class ViewModelAssembly: Assembly { func assemble(container: Container) { - container.register(WelcomeViewModel.self) { _ in - return WelcomeViewModel() + container.register(WelcomeViewModel.self) { res in + WelcomeViewModel( + coordinator: res.resolve(WelcomeCoordinator.self)! + ) }.inObjectScope(.container) } } diff --git a/SyncPod/view/viewcontroller/WelcomeViewController.swift b/SyncPod/view/viewcontroller/WelcomeViewController.swift index 4692fec..3dff73a 100644 --- a/SyncPod/view/viewcontroller/WelcomeViewController.swift +++ b/SyncPod/view/viewcontroller/WelcomeViewController.swift @@ -12,7 +12,7 @@ import RxCocoa class WelcomeViewConstoller: UIViewController { let disposeBag = DisposeBag() - var viewModel: WelcomeViewModel? + var viewModel: WelcomeViewModel! @IBOutlet weak var signInButton: UIBarButtonItem! @IBOutlet weak var signUpButton: UIBarButtonItem! @@ -20,15 +20,17 @@ class WelcomeViewConstoller: UIViewController { override func viewDidLoad() { super.viewDidLoad() + print(viewModel) + setUpDataBinding() } private func setUpDataBinding() { signInButton.rx.tap - .subscribe({ _ in self.viewModel?.onSignInClicked() }) + .subscribe({ _ in self.viewModel.onSignInClicked() }) .disposed(by: disposeBag) signUpButton.rx.tap - .subscribe({ _ in self.viewModel?.onSignUpClicked() }) + .subscribe({ _ in self.viewModel.onSignUpClicked() }) .disposed(by: disposeBag) } } diff --git a/SyncPod/viewmodel/WelcomeViewModel.swift b/SyncPod/viewmodel/WelcomeViewModel.swift index afdec42..a519310 100644 --- a/SyncPod/viewmodel/WelcomeViewModel.swift +++ b/SyncPod/viewmodel/WelcomeViewModel.swift @@ -9,13 +9,16 @@ import Foundation class WelcomeViewModel { - var coordinator: WelcomeCoordinator? + let coordinator: WelcomeCoordinator + init(coordinator: WelcomeCoordinator) { + self.coordinator = coordinator + } func onSignInClicked() { - coordinator?.navigateToSignIn() + coordinator.navigateToSignIn() } func onSignUpClicked() { - coordinator?.navigateToSignUp() + coordinator.navigateToSignUp() } } From 205bf8ee3fac979cea77b564c5820fa8af54f659 Mon Sep 17 00:00:00 2001 From: Mori Atsushi Date: Wed, 6 Jun 2018 19:22:09 +0900 Subject: [PATCH 3/3] =?UTF-8?q?[fix]=20rebase=E3=83=9F=E3=82=B9=E3=82=92?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SyncPod/coordinator/WelcomeCoordinator.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/SyncPod/coordinator/WelcomeCoordinator.swift b/SyncPod/coordinator/WelcomeCoordinator.swift index 15de3cc..4bb6e71 100644 --- a/SyncPod/coordinator/WelcomeCoordinator.swift +++ b/SyncPod/coordinator/WelcomeCoordinator.swift @@ -22,6 +22,7 @@ class WelcomeCoordinator: BaseCoordinator { } func start() { + window.rootViewController = nowViewController } func navigateToSignIn() {