swift添加load方法
2023-03-01 本文已影响0人
太平洋_cfd2
https://juejin.cn/post/6844904014832730126
使用推荐里的方法时,带有泛型的类无法加载,其他任何类都行
class MMBookListPageViewService: MMServices {
func login() -> MMHomePageModel {
return MMHomePageModel()
}
}
extension MMBookListPageViewService: MMLoadProtocol {
static func preLoad() {
MMAssemblyManager.share.push { container in
container.autoregister(MMBookListPageViewModel.self, initializer: MMBookListPageViewModel.init)
container.autoregister(MMBookListPageViewService.self, initializer: MMBookListPageViewService.init)
}
}
}
以下就不行
class MMBookListPageViewModel: MMViewModel<MMBookListPageViewService> {
}
这个带有泛型的类,添加了MMLoadProtocol协议,也不会调用
其他任何类都行,无论是否继承NSObject