Last active
September 3, 2019 07:53
-
-
Save milankamilya/159d01ed7f15768c08b83e2eda6bfeee to your computer and use it in GitHub Desktop.
Boilerplate Code / Snippets for MVVM with Coordinator Architecture
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let navigationController: UINavigationController | |
private static let storyboardName: String = <#Module Storyboard Name#> | |
private let httpService: <#HTTP Service Type#> | |
private let storyBoard = UIStoryboard(name: storyboardName, bundle: nil) | |
lazy var rootViewController: <#View Controller#> = { | |
if let lvc = self.storyBoard.instantiateViewController( | |
withIdentifier: <#View Controller#>.className | |
) as? <#View Controller#> { | |
return lvc | |
} else { | |
return <#View Controller#>() | |
} | |
}() | |
private lazy var viewModel: <#ViewModel Type#> = { | |
let viewModel = <#ViewModel Type#>(httpService: <#HTTP Service Type#>) | |
return viewModel | |
}() | |
init( | |
httpService: <#HTTP Service Type#>, | |
navigationController: UINavigationController | |
) { | |
self.httpService = httpService | |
self.navigationController = navigationController | |
} | |
@objc public override func start() { | |
rootViewController.viewModel = viewModel | |
viewModel.popViewController.popViewController = { [weak self]success in | |
DispatchQueue.main.async { | |
self?.navigationController.popViewController(animated: true) | |
self?.readyToFinish() | |
} | |
} | |
navigationController.pushViewController(rootViewController, animated: true) | |
} | |
@objc public override func finish() { | |
//TODO | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MARK: - IBOutlets | |
// MARK: - Public Properties | |
override var viewModel: BaseViewModel? { | |
get { return pvtViewModel } | |
set { | |
if let newValue = newValue as? <#Custom ViewModel#> { | |
pvtViewModel = newValue | |
} else { preconditionFailure("Please send proper ViewModel object") } | |
} | |
} | |
// MARK: - File Private Properties | |
fileprivate var pvtViewModel: <#Custom ViewModel#>? | |
// MARK: - Life Cycle Methods | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
initialSetup() | |
} | |
override func viewWillAppear(_ animated: Bool) { | |
super.viewWillAppear(animated) | |
pvtViewModel?.viewWillAppear() | |
} | |
override func viewWillDisappear(_ animated: Bool) { | |
super.viewWillDisappear(animated) | |
pvtViewModel?.viewWillDisappear() | |
} | |
// MARK: - Initial Setup | |
func initialSetup() { | |
pvtViewModel?.reloadUI = { [weak self]() in | |
DispatchQueue.main.async { | |
} | |
} | |
} | |
// MARK: - Customize View | |
// MARK: - IBActions | |
// MARK: - Utility |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MARK: - Public Properties | |
// MARK: - Public Closures | |
// MARK: - Private Property | |
private let httpService: <#HTTP Service Class Type#> | |
// MARK: - Init | |
init(httpService: <#HTTP Service Class Type#> ) { | |
self.httpService = httpService | |
} | |
// MARK: - Init | |
// MARK: - Lifecycle Methods | |
func viewDidLoad() { | |
} | |
func viewWillAppear() { | |
} | |
func viewWillDisappear() { | |
} | |
// MARK: - Server API Call | |
// MARK: - Data Processing | |
// MARK: - Process TableView Data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment