// // 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" : @"RQWebViewController", /*LoginModule*/ @"RQLoginViewModel" : @"RQLoginViewController", @"RQRegisterViewModel" : @"RQRegisterViewController", @"RQVerificationSmsCodeViewModel" : @"RQVerificationSmsCodeViewController", @"RQUpdatePasswordViewModel" : @"RQUpdatePasswordViewController", /*HomePageModular*/ // @"HomeBaseViewModel" : @"HomeBaseVC", // @"RQHomePageViewModel" : @"RQHomePageViewController", @"RQHomePageViewModel" : @"HomeBaseVC", @"RQHomeSubPageViewModel" : @"RQHomeSubPageViewController", @"RQHomePageSubjectOneOrFourViewModel" : @"RQHomePageSubjectOneOrFourViewController", @"RQExerciseViewModel" : @"RQExerciseViewController", @"RQExerciseSubViewModel" : @"RQExerciseSubViewController", @"RQCatalogueViewModel" : @"RQCatalogueViewController", @"RQTestResultsViewModel" : @"RQTestResultsViewController", @"RQHoursBeforeExamHomeViewModel" : @"RQHoursBeforeExamHomeViewController", /*CommunityModule*/ // @"RQCommunityViewModel" : @"RQCommunityViewController", @"RQCommunityViewModel" : @"LearnDrivingVC", /*TimeModule*/ // @"RQTimeViewModel" : @"RQTimeViewController", @"RQTimeViewModel" : @"TimingBaseVC", /*DiscoverModule*/ // @"RQDiscoverViewModel" : @"RQDiscoverViewController", @"RQDiscoverViewModel" : @"NeighbouringVC", /*ProfileModule*/ // @"RQProfileViewModel" : @"RQProfileViewController", @"RQProfileViewModel" : @"FunctionVC", @"RQUserInfoViewModel" : @"RQUserInfoViewController", @"RQActivateVIPViewModel" : @"RQActivateVIPViewController", /*OtherModule*/ @"RQVideoCatalogueViewModel" : @"RQVideoCatalogueViewController", @"RQVideoDetailViewModel" : @"RQVideoDetailViewController", @"RQVideoDetailSubPageViewModel" : @"RQVideoDetailSubPageViewController", }; } @end