美文网首页
swift添加load方法

swift添加load方法

作者: 太平洋_cfd2 | 来源:发表于2023-03-01 11:42 被阅读0次

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

相关文章

网友评论

      本文标题:swift添加load方法

      本文链接:https://www.haomeiwen.com/subject/xswrldtx.html