123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- //
- // RQRouter.m
- // RQCommon
- //
- // Created by 张嵘 on 2018/11/16.
- // Copyright © 2018 张嵘. All rights reserved.
- //
- #import "RQRouter.h"
- @interface RQRouter ()
- /// viewModel到viewController的映射
- @property (nonatomic, copy) NSDictionary *viewModelViewMappings;
- @end
- @implementation RQRouter
- static RQRouter *sharedInstance_ = nil;
- + (id)allocWithZone:(struct _NSZone *)zone
- {
- static dispatch_once_t onceToken;
- dispatch_once(&onceToken, ^{
- sharedInstance_ = [super allocWithZone:zone];
- });
- return sharedInstance_;
- }
- - (id)copyWithZone:(NSZone *)zone
- {
- return sharedInstance_;
- }
- + (instancetype)sharedInstance {
- static dispatch_once_t onceToken;
- dispatch_once(&onceToken, ^{
- sharedInstance_ = [[self alloc] init];
- });
- return sharedInstance_;
- }
- - (RQBaseViewController *)viewControllerForViewModel:(RQBaseViewModel *)viewModel {
- NSString *viewController = self.viewModelViewMappings[NSStringFromClass(viewModel.class)];
-
- NSParameterAssert([NSClassFromString(viewController) isSubclassOfClass:[RQBaseViewController class]]);
- NSParameterAssert([NSClassFromString(viewController) instancesRespondToSelector:@selector(initWithViewModel:)]);
-
- return [[NSClassFromString(viewController) alloc] initWithViewModel:viewModel];
- }
- /// 这里是viewModel -> ViewController的映射
- /// If You Use Push 、 Present 、 ResetRootViewController ,You Must Config This Dict
- - (NSDictionary *)viewModelViewMappings {
- return @{/*MainModule*/
- @"RQNewFeatureViewModel" : @"RQNewFeatureViewController",
- @"RQMainTabBarViewModel" : @"RQMainTabBarViewController",
- /*Base*/
- @"RQWebViewModel" : @"RQWebViewViewController",
- /*LoginModule*/
- @"RQLoginViewModel" : @"RQLoginViewController",
- @"RQRegisterViewModel" : @"RQRegisterViewController",
- @"RQVerificationSmsCodeViewModel" : @"RQVerificationSmsCodeViewController",
- @"RQUpdatePasswordViewModel" : @"RQUpdatePasswordViewController",
- /*HomePageModular*/
- @"HomeBaseViewModel" : @"HomeBaseVC",
- @"RQHomePageViewModel" : @"RQHomePageViewController",
- @"RQHomeSubPageViewModel" : @"RQHomeSubPageViewController",
- @"RQHomePageSubjectOneOrFourViewModel" : @"RQHomePageSubjectOneOrFourViewController",
- @"RQHomeSubPageVideoScrollViewModel" : @"RQHomeSubPageVideoScrollViewController",
- @"RQHomeSubPageVideoScrollSubViewModel": @"RQHomeSubPageVideoScrollSubViewController",
- @"RQHomeSubPageListViewModel" : @"RQHomeSubPageListViewController",
- @"RQHomeSubPageLocalTopicListViewModel": @"RQHomeSubPageLocalTopicListViewController",
- @"RQHomeSubPageSortViewModel" : @"RQHomeSubPageSortViewController",
- @"RQWrongAndCollectionViewModel" : @"RQWrongAndCollectionVC",
- @"RQSimulationResultsViewModel" : @"RQSimulationResultsViewController",
- @"RQSimulationTestTopicsViewModel" : @"RQSimulationTestTopicsViewController",
- @"RQExerciseViewModel" : @"RQExerciseViewController",
- @"RQExerciseSubViewModel" : @"RQExerciseSubViewController",
- @"RQCatalogueViewModel" : @"RQCatalogueViewController",
- @"RQTestResultsViewModel" : @"RQTestResultsViewController",
- @"RQHoursBeforeExamHomeViewModel" : @"RQHoursBeforeExamHomeViewController",
- /*Module*/
- /*Module*/
- /*ProfileModule*/
- @"RQProfileViewModel" : @"RQProfileViewController",
- @"RQUserInfoViewModel" : @"RQUserInfoViewController",
- @"RQActivateVIPViewModel" : @"RQActivateVIPViewController",
- @"RQFreeTryViewModel" : @"RQFreeTryViewController",
- @"RQLearningMaterialsViewModel" : @"RQLearningMaterialsViewController",
- @"RQLearningMaterialsDetailViewModel" : @"RQLearningMaterialsDetailViewController",
- @"RQVersionUpdateViewModel" : @"RQVersionUpdateViewController",
- @"RQFeedbackAndHelpViewModel" : @"RQFeedbackAndHelpViewController",
-
- @"RQVideoCatalogueViewModel" : @"RQVideoCatalogueViewController",
- @"RQExerciseSettingViewModel" : @"RQExerciseSettingViewController",
- @"RQVideoDetailViewModel" : @"RQVideoDetailViewController",
- @"RQVideoDetailSubPageViewModel" : @"RQVideoDetailSubPageViewController",
- @"RQDspVideoDetailViewModel" : @"RQDspVideoDetailViewController",
- @"RQExplainVideoViewModel" : @"RQExplainVideoViewController",
-
- };
- }
- @end
|