RQRouter.m 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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" : @"RQWebViewController",
  48. /*LoginModule*/
  49. @"RQLoginViewModel" : @"RQLoginViewController",
  50. @"RQRegisterViewModel" : @"RQRegisterViewController",
  51. @"RQVerificationSmsCodeViewModel" : @"RQVerificationSmsCodeViewController",
  52. @"RQUpdatePasswordViewModel" : @"RQUpdatePasswordViewController",
  53. /*HomePageModular*/
  54. // @"HomeBaseViewModel" : @"HomeBaseVC",
  55. // @"RQHomePageViewModel" : @"RQHomePageViewController",
  56. @"RQHomePageViewModel" : @"HomeBaseVC",
  57. @"RQHomeSubPageViewModel" : @"RQHomeSubPageViewController",
  58. @"RQHomePageSubjectOneOrFourViewModel" : @"RQHomePageSubjectOneOrFourViewController",
  59. @"RQExerciseViewModel" : @"RQExerciseViewController",
  60. @"RQExerciseSubViewModel" : @"RQExerciseSubViewController",
  61. @"RQCatalogueViewModel" : @"RQCatalogueViewController",
  62. @"RQTestResultsViewModel" : @"RQTestResultsViewController",
  63. @"RQHoursBeforeExamHomeViewModel" : @"RQHoursBeforeExamHomeViewController",
  64. /*CommunityModule*/
  65. // @"RQCommunityViewModel" : @"RQCommunityViewController",
  66. @"RQCommunityViewModel" : @"LearnDrivingVC",
  67. /*TimeModule*/
  68. // @"RQTimeViewModel" : @"RQTimeViewController",
  69. @"RQTimeViewModel" : @"TimingBaseVC",
  70. /*DiscoverModule*/
  71. // @"RQDiscoverViewModel" : @"RQDiscoverViewController",
  72. @"RQDiscoverViewModel" : @"NeighbouringVC",
  73. /*ProfileModule*/
  74. // @"RQProfileViewModel" : @"RQProfileViewController",
  75. @"RQProfileViewModel" : @"FunctionVC",
  76. @"RQUserInfoViewModel" : @"RQUserInfoViewController",
  77. @"RQActivateVIPViewModel" : @"RQActivateVIPViewController",
  78. /*OtherModule*/
  79. @"RQVideoCatalogueViewModel" : @"RQVideoCatalogueViewController",
  80. @"RQVideoDetailViewModel" : @"RQVideoDetailViewController",
  81. @"RQVideoDetailSubPageViewModel" : @"RQVideoDetailSubPageViewController",
  82. };
  83. }
  84. @end