RQRouter.m 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. //
  2. // RQRouter.m
  3. // RQCommon
  4. //
  5. // Created by 张嵘 on 2018/11/16.
  6. // Copyright © 2018 张嵘. All rights reserved.
  7. //
  8. #import "RQRouter.h"
  9. @interface RQRouter ()
  10. /// viewModel到viewController的映射
  11. @property (nonatomic, copy) NSDictionary *viewModelViewMappings;
  12. @end
  13. @implementation RQRouter
  14. static RQRouter *sharedInstance_ = nil;
  15. + (id)allocWithZone:(struct _NSZone *)zone
  16. {
  17. static dispatch_once_t onceToken;
  18. dispatch_once(&onceToken, ^{
  19. sharedInstance_ = [super allocWithZone:zone];
  20. });
  21. return sharedInstance_;
  22. }
  23. - (id)copyWithZone:(NSZone *)zone
  24. {
  25. return sharedInstance_;
  26. }
  27. + (instancetype)sharedInstance {
  28. static dispatch_once_t onceToken;
  29. dispatch_once(&onceToken, ^{
  30. sharedInstance_ = [[self alloc] init];
  31. });
  32. return sharedInstance_;
  33. }
  34. - (RQBaseViewController *)viewControllerForViewModel:(RQBaseViewModel *)viewModel {
  35. NSString *viewController = self.viewModelViewMappings[NSStringFromClass(viewModel.class)];
  36. NSParameterAssert([NSClassFromString(viewController) isSubclassOfClass:[RQBaseViewController class]]);
  37. NSParameterAssert([NSClassFromString(viewController) instancesRespondToSelector:@selector(initWithViewModel:)]);
  38. return [[NSClassFromString(viewController) alloc] initWithViewModel:viewModel];
  39. }
  40. /// 这里是viewModel -> ViewController的映射
  41. /// If You Use Push 、 Present 、 ResetRootViewController ,You Must Config This Dict
  42. - (NSDictionary *)viewModelViewMappings {
  43. return @{/*MainModule*/
  44. @"RQNewFeatureViewModel" : @"RQNewFeatureViewController",
  45. @"RQMainTabBarViewModel" : @"RQMainTabBarViewController",
  46. /*Base*/
  47. @"RQWebViewModel" : @"RQWebViewViewController",
  48. /*LoginModule*/
  49. @"RQLoginViewModel" : @"RQLoginViewController",
  50. @"RQRegisterViewModel" : @"RQRegisterViewController",
  51. @"RQVerificationSmsCodeViewModel" : @"RQVerificationSmsCodeViewController",
  52. @"RQUpdatePasswordViewModel" : @"RQUpdatePasswordViewController",
  53. /*HomePageModular*/
  54. @"HomeBaseViewModel" : @"HomeBaseVC",
  55. @"RQHomePageViewModel" : @"RQHomePageViewController",
  56. @"RQHomeSubPageViewModel" : @"RQHomeSubPageViewController",
  57. @"RQHomePageSubjectOneOrFourViewModel" : @"RQHomePageSubjectOneOrFourViewController",
  58. @"RQHomeSubPageVideoScrollViewModel" : @"RQHomeSubPageVideoScrollViewController",
  59. @"RQHomeSubPageVideoScrollSubViewModel": @"RQHomeSubPageVideoScrollSubViewController",
  60. @"RQHomeSubPageListViewModel" : @"RQHomeSubPageListViewController",
  61. @"RQHomeSubPageLocalTopicListViewModel": @"RQHomeSubPageLocalTopicListViewController",
  62. @"RQHomeSubPageSortViewModel" : @"RQHomeSubPageSortViewController",
  63. @"RQWrongAndCollectionViewModel" : @"RQWrongAndCollectionVC",
  64. @"RQSimulationResultsViewModel" : @"RQSimulationResultsViewController",
  65. @"RQSimulationTestTopicsViewModel" : @"RQSimulationTestTopicsViewController",
  66. @"RQExerciseViewModel" : @"RQExerciseViewController",
  67. @"RQExerciseSubViewModel" : @"RQExerciseSubViewController",
  68. @"RQCatalogueViewModel" : @"RQCatalogueViewController",
  69. @"RQTestResultsViewModel" : @"RQTestResultsViewController",
  70. @"RQHoursBeforeExamHomeViewModel" : @"RQHoursBeforeExamHomeViewController",
  71. /*Module*/
  72. /*Module*/
  73. /*ProfileModule*/
  74. @"RQProfileViewModel" : @"RQProfileViewController",
  75. @"RQUserInfoViewModel" : @"RQUserInfoViewController",
  76. @"RQActivateVIPViewModel" : @"RQActivateVIPViewController",
  77. @"RQFreeTryViewModel" : @"RQFreeTryViewController",
  78. @"RQLearningMaterialsViewModel" : @"RQLearningMaterialsViewController",
  79. @"RQLearningMaterialsDetailViewModel" : @"RQLearningMaterialsDetailViewController",
  80. @"RQVersionUpdateViewModel" : @"RQVersionUpdateViewController",
  81. @"RQFeedbackAndHelpViewModel" : @"RQFeedbackAndHelpViewController",
  82. @"RQVideoCatalogueViewModel" : @"RQVideoCatalogueViewController",
  83. @"RQExerciseSettingViewModel" : @"RQExerciseSettingViewController",
  84. @"RQVideoDetailViewModel" : @"RQVideoDetailViewController",
  85. @"RQVideoDetailSubPageViewModel" : @"RQVideoDetailSubPageViewController",
  86. @"RQDspVideoDetailViewModel" : @"RQDspVideoDetailViewController",
  87. @"RQExplainVideoViewModel" : @"RQExplainVideoViewController",
  88. };
  89. }
  90. @end