我有 MVVM-C 拱门。每个UIViewController
都有一个ViewModel
andCoordinatorDelegate
来通知Coordinator
何时需要执行导航。创建 VC 的代码会重复自己,我认为创建一个超类来统一创建 VC 的所有静态函数会很棒。像这样:
import UIKit
class MVVMCViewController: UIViewController {
weak var coordinatorDelegate: CoordinatorDelegate?
var viewModel: Modelling?
static func initVC(storyboard: Storyboard,
coordinatorDelegate: CoordinatorDelegate?,
viewModel: Modelling?) -> Self {
let viewController = Self.instantiate(in: storyboard)
viewController.coordinatorDelegate = coordinatorDelegate
viewController.viewModel = viewModel
return viewController
}
}
所有人CoordinatorDelegateProtocols
都将继承CoordinatorDelegate
,所有人都ViewModels
将继承自Modelling
但是子类化工作并不顺利。
有任何想法吗?