RQRouter.m 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. @"RQHomePageViewModel" : @"RQHomePageViewController",
  55. @"RQStrongViewModel" : @"StrongVC",
  56. @"LightingAndSoundViewModel" : @"LightingAndSoundVC",
  57. @"RQHomeSubPageViewModel" : @"RQHomeSubPageViewController",
  58. @"RQHomePageSubjectOneOrFourViewModel" : @"RQHomePageSubjectOneOrFourViewController",
  59. @"RQErrorAndCollectViewModel" : @"RQErrorAndCollectViewController",
  60. @"RQErrorViewModel" : @"RQErrorViewController",
  61. @"RQCollectViewModel" : @"RQCollectViewController",
  62. @"RQHomePageTeachVideoViewModel" : @"RQHomePageTeachVideoViewController",
  63. @"RQHomePageTeachVideoListViewModel" : @"RQHomePageTeachVideoListViewController",
  64. @"RQPlaceListViewModel" : @"RQPlaceListViewController",
  65. @"RQPlaceDetailViewModel" : @"RQPlaceDetailViewController",
  66. @"RQExerciseViewModel" : @"RQExerciseViewController",
  67. @"RQExerciseSubViewModel" : @"RQExerciseSubViewController",
  68. @"RQSimulateExamViewModel" : @"RQSimulateExamViewController",
  69. @"RQCatalogueViewModel" : @"RQCatalogueViewController",
  70. @"RQExamResultViewModel" : @"RQExamResultViewController",
  71. @"RQExamProbabilityViewModel" : @"RQExamProbabilityViewController",
  72. @"RQSpecialPractiseViewModel" : @"RQSpecialPractiseViewController",
  73. @"RQChapterAndPointListViewModel" : @"RQChapterAndPointListViewController",
  74. @"RQHoursBeforeExamHomeViewModel" : @"RQHoursBeforeExamHomeViewController",
  75. /*TimeModule*/
  76. @"RQTimeViewModel" : @"RQTimeViewController",
  77. @"NYTheoryTimeViewModel" : @"NYTheoryTimeVC",
  78. // @"RQTimeViewModel" : @"TimingBaseVC",
  79. /*DiscoverModule*/
  80. // @"RQDiscoverViewModel" : @"RQDiscoverViewController",
  81. @"RQDiscoverViewModel" : @"SearchBase",
  82. /*ProfileModule*/
  83. //#if DEBUG
  84. // @"RQProfileViewModel" : @"RQProfileViewController",
  85. //#else
  86. @"RQProfileViewModel" : @"FunctionVC",
  87. //#endif
  88. @"RQSettingViewModel" : @"RQSettingViewController",
  89. @"RQAboutViewModel" : @"RQAboutViewController",
  90. @"RQChooseCarTypeViewModel" : @"RQChooseCarTypeViewController",
  91. @"RQSynchronizationViewModel" : @"RQSynchronizationViewController",
  92. @"RQUserInfoViewModel" : @"RQUserInfoViewController",
  93. @"RQActivateVIPViewModel" : @"RQActivateVIPViewController",
  94. /*OtherModule*/
  95. @"RQVideoCatalogueViewModel" : @"RQVideoCatalogueViewController",
  96. @"RQVideoDetailViewModel" : @"RQVideoDetailViewController",
  97. @"RQVideoDetailSubPageViewModel" : @"RQVideoDetailSubPageViewController",
  98. @"RQVipViewModel" : @"RQVipViewController",
  99. @"RQPayViewModel" : @"RQPayViewController",
  100. @"RQVipCenterViewModel" : @"RQVipCenterViewController",
  101. @"RQVipCenterSubViewModel" : @"RQVipCenterSubViewController",
  102. @"RQVipCenterSubListViewModel" : @"RQVipCenterSubListViewController",
  103. @"RQDspVideoDetailViewModel" : @"RQDspVideoDetailViewController",
  104. @"RQRetrainViewModel" : @"RQRetrainViewController",
  105. @"RQRetrainOrderViewModel" : @"RQRetrainOrderViewController",
  106. @"RQStudentChangeSchoolViewModel" : @"StudentChangeSchoolVC",
  107. @"RQExplainVideoViewModel" : @"RQExplainVideoViewController",
  108. };
  109. }
  110. @end