text
stringlengths
9
39.2M
dir
stringlengths
26
295
lang
stringclasses
185 values
created_date
timestamp[us]
updated_date
timestamp[us]
repo_name
stringlengths
1
97
repo_full_name
stringlengths
7
106
star
int64
1k
183k
len_tokens
int64
1
13.8M
```objective-c // // EcoMainViewController.m // BigShow1949 // // Created by apple on 17/8/16. // #import "EcoMainViewController.h" #import "EcoRouterTool.h" #import <WebKit/WebKit.h> //#import "BaseViewController.h" @interface EcoMainViewController ()<WKNavigationDelegate> @property (nonatomic, strong) WKWebView *wkWebView; @end @implementation EcoMainViewController #pragma mark - lifeCycle - (void)viewDidLoad { [super viewDidLoad]; //UI [self initUI]; //html [self loadWebView]; // Do any additional setup after loading the view, typically from a nib. } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; self.wkWebView.navigationDelegate = self; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; self.wkWebView.navigationDelegate = nil; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)dealloc { self.wkWebView.navigationDelegate = nil; self.wkWebView = nil; } #pragma mark - UI - (void)initUI { [self.view addSubview:self.wkWebView]; } - (WKWebView *)wkWebView { if (!_wkWebView) { _wkWebView = [[WKWebView alloc] initWithFrame:self.view.bounds]; } return _wkWebView; } #pragma mark - webView - (void)loadWebView { NSString *path = [[NSBundle mainBundle] pathForResource:@"router" ofType:@"html"]; NSString *htmlString = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil]; NSLog(@"htmlString===%@",htmlString); [_wkWebView loadHTMLString:htmlString baseURL:nil]; } #pragma mark - delegate - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler { WKNavigationActionPolicy policy = WKNavigationActionPolicyAllow; NSURL *url = navigationAction.request.URL; if (WKNavigationTypeLinkActivated == navigationAction.navigationType&& [url.scheme isEqualToString:@"eco"]) { [self doUrl:url.absoluteString]; policy = WKNavigationActionPolicyCancel; } decisionHandler(policy); } #pragma mark - - (void)doUrl:(NSString *)urlString { NSLog(@"urlString +==== %@",urlString); [EcoRouterTool openUrl:urlString from:self]; } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Router/EcoRouterDemo/EcoMainViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
543
```objective-c // // EcoMainViewController.h // BigShow1949 // // Created by apple on 17/8/16. // #import <UIKit/UIKit.h> @interface EcoMainViewController : UIViewController @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Router/EcoRouterDemo/EcoMainViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
46
```objective-c // // RouterTool.h // EcoRouterDemo // // Created by on 2017/3/5. // #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> #import "UIViewController+Router.h" @interface EcoRouterTool : NSObject /** * * * @param fileName plist * * @return */ + (NSDictionary *)getRouterPlistName:(NSString *)fileName; /** * PlistRouterUrl * * @param fileName plist */ + (void)registerRouterListFromPlist:(NSString *)fileName; /** * RouterLink * * @param url * * @return UIViewController */ + (UIViewController *)openUrl:(NSString *)url; /** * RouterLink * * @param url * @param userInfo * * @return UIViewController */ + (UIViewController *)openUrl:(NSString *)url withUserInfo:(NSDictionary *)userInfo; /** * RouterLinkURLUserInfo * * @param url * @param viewController * */ + (void)openUrl:(NSString *)url from:(UIViewController *)viewController; /** * RouterLinkclassname * * @param className * @param userInfo * @param viewController * */ + (void)openClass:(NSString *)className withUserInfo:(NSDictionary *)userInfo from:(UIViewController *)viewController; /** * RouterLinkURLUserInfo * * @param url * @param viewController * */ + (void)openUrl:(NSString *)url withUserInfo:(NSDictionary *)userInfo from:(UIViewController *)viewController; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Router/EcoRouterDemo/Router/EcoRouterTool.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
332
```objective-c // // RouterTool.m // EcoRouterDemo // // Created by on 2017/3/5. // #import "EcoRouterTool.h" #import "EcoRouter.h" #define ROUTER_TABLE @"RouterList" @implementation EcoRouterTool // + (void)load { [self registerRouterListFromPlist:ROUTER_TABLE]; } // + (NSDictionary *)getRouterPlistName:(NSString *)fileName { fileName = (fileName && ![fileName isKindOfClass:[NSNull class]]) ? fileName : @""; NSString *filePath = [[NSBundle mainBundle] pathForResource:fileName ofType:@"plist"]; NSDictionary *routerDic = [NSDictionary dictionaryWithContentsOfFile:filePath]; return routerDic; } //Router + (void)registerRouterListFromPlist:(NSString *)fileName { NSDictionary *routerDic = [self getRouterPlistName:fileName]; for (NSString *key in routerDic.allKeys) { [EcoRouter registerURLPattern:routerDic[key] toObjectHandler:^id(NSDictionary *routerParameters) { UIViewController *viewController = [[NSClassFromString(key) alloc] init]; if ([viewController isKindOfClass:[UIViewController class]]) { viewController.paramDic = routerParameters; } return viewController; }]; } } //RouterLink + (UIViewController *)openUrl:(NSString *)url { return [self openUrl:url withUserInfo:nil]; } //RouterLink + (UIViewController *)openUrl:(NSString *)url withUserInfo:(NSDictionary *)userInfo { return [EcoRouter objectForURL:url withUserInfo:userInfo]; } //RouterLink + (void)openUrl:(NSString *)url from:(UIViewController *)viewController { [self openUrl:url withUserInfo:nil from:viewController]; } //RouterLinkclassname + (void)openClass:(NSString *)className withUserInfo:(NSDictionary *)userInfo from:(UIViewController *)viewController { NSDictionary *routerDic = [self getRouterPlistName:ROUTER_TABLE]; NSString *url = routerDic[className]; [self openUrl:url withUserInfo:userInfo from:viewController]; } //RouterLink + (void)openUrl:(NSString *)url withUserInfo:(NSDictionary *)userInfo from:(UIViewController *)viewController { if (![viewController isKindOfClass:[UIViewController class]] || !viewController) { return; } UIViewController *routerViewController = [EcoRouter objectForURL:url withUserInfo:userInfo]; if ([routerViewController isKindOfClass:[UIViewController class]]) { if ([viewController isKindOfClass:[UINavigationController class]]) { [(UINavigationController *)viewController pushViewController:routerViewController animated:YES]; } else { UINavigationController *routerNav = [[UINavigationController alloc] initWithRootViewController:routerViewController]; [viewController presentViewController:routerNav animated:YES completion:^{ }]; } } else { UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:@"" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"" style:UIAlertActionStyleCancel handler:nil]; [alertController addAction:cancelAction]; [viewController presentViewController:alertController animated:YES completion:^{ }]; } } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Router/EcoRouterDemo/Router/EcoRouterTool.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
668
```objective-c // // EcoRouter.m // EcoRouterDemo // // Created by on 2017/3/5. // #import "EcoRouter.h" #import <objc/runtime.h> static NSString * const Eco_ROUTER_WILDCARD_CHARACTER = @"~"; static NSString *specialCharacters = @"/?&."; NSString *const EcoRouterParameterURL = @"EcoRouterParameterURL"; NSString *const EcoRouterParameterCompletion = @"EcoRouterParameterCompletion"; NSString *const EcoRouterParameterUserInfo = @"EcoRouterParameterUserInfo"; @interface EcoRouter () /** * URL * @{@"beauty": @{@":id": {@"_", [block copy]}}} */ @property (nonatomic) NSMutableDictionary *routes; @end @implementation EcoRouter + (instancetype)sharedInstance { static EcoRouter *instance = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ instance = [[self alloc] init]; }); return instance; } + (void)registerURLPattern:(NSString *)URLPattern toHandler:(EcoRouterHandler)handler { [[self sharedInstance] addURLPattern:URLPattern andHandler:handler]; } + (void)deregisterURLPattern:(NSString *)URLPattern { [[self sharedInstance] removeURLPattern:URLPattern]; } + (void)openURL:(NSString *)URL { [self openURL:URL completion:nil]; } + (void)openURL:(NSString *)URL completion:(void (^)(id result))completion { [self openURL:URL withUserInfo:nil completion:completion]; } + (void)openURL:(NSString *)URL withUserInfo:(NSDictionary *)userInfo completion:(void (^)(id result))completion { /** * changed by clei 2017-3-5 */ //URL = [URL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; URL = [URL stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]; NSMutableDictionary *parameters = [[self sharedInstance] extractParametersFromURL:URL]; [parameters enumerateKeysAndObjectsUsingBlock:^(id key, NSString *obj, BOOL *stop) { if ([obj isKindOfClass:[NSString class]]) { //parameters[key] = [obj stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; parameters[key] = [obj stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]; } }]; if (parameters) { EcoRouterHandler handler = parameters[@"block"]; if (completion) { parameters[EcoRouterParameterCompletion] = completion; } if (userInfo) { parameters[EcoRouterParameterUserInfo] = userInfo; } if (handler) { [parameters removeObjectForKey:@"block"]; handler(parameters); } } } + (BOOL)canOpenURL:(NSString *)URL { return [[self sharedInstance] extractParametersFromURL:URL] ? YES : NO; } + (NSString *)generateURLWithPattern:(NSString *)pattern parameters:(NSArray *)parameters { NSInteger startIndexOfColon = 0; NSMutableArray *placeholders = [NSMutableArray array]; for (int i = 0; i < pattern.length; i++) { NSString *character = [NSString stringWithFormat:@"%c", [pattern characterAtIndex:i]]; if ([character isEqualToString:@":"]) { startIndexOfColon = i; } if ([specialCharacters rangeOfString:character].location != NSNotFound && i > (startIndexOfColon + 1) && startIndexOfColon) { NSRange range = NSMakeRange(startIndexOfColon, i - startIndexOfColon); NSString *placeholder = [pattern substringWithRange:range]; if (![self checkIfContainsSpecialCharacter:placeholder]) { [placeholders addObject:placeholder]; startIndexOfColon = 0; } } if (i == pattern.length - 1 && startIndexOfColon) { NSRange range = NSMakeRange(startIndexOfColon, i - startIndexOfColon + 1); NSString *placeholder = [pattern substringWithRange:range]; if (![self checkIfContainsSpecialCharacter:placeholder]) { [placeholders addObject:placeholder]; } } } __block NSString *parsedResult = pattern; [placeholders enumerateObjectsUsingBlock:^(NSString *obj, NSUInteger idx, BOOL * _Nonnull stop) { idx = parameters.count > idx ? idx : parameters.count - 1; parsedResult = [parsedResult stringByReplacingOccurrencesOfString:obj withString:parameters[idx]]; }]; return parsedResult; } + (id)objectForURL:(NSString *)URL withUserInfo:(NSDictionary *)userInfo { EcoRouter *router = [EcoRouter sharedInstance]; //URL = [URL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; URL = [URL stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]; NSMutableDictionary *parameters = [router extractParametersFromURL:URL]; EcoRouterObjectHandler handler = parameters[@"block"]; if (handler) { if (userInfo) { parameters[EcoRouterParameterUserInfo] = userInfo; } [parameters removeObjectForKey:@"block"]; return handler(parameters); } return nil; } + (id)objectForURL:(NSString *)URL { return [self objectForURL:URL withUserInfo:nil]; } + (void)registerURLPattern:(NSString *)URLPattern toObjectHandler:(EcoRouterObjectHandler)handler { [[self sharedInstance] addURLPattern:URLPattern andObjectHandler:handler]; } - (void)addURLPattern:(NSString *)URLPattern andHandler:(EcoRouterHandler)handler { NSMutableDictionary *subRoutes = [self addURLPattern:URLPattern]; if (handler && subRoutes) { subRoutes[@"_"] = [handler copy]; } } - (void)addURLPattern:(NSString *)URLPattern andObjectHandler:(EcoRouterObjectHandler)handler { NSMutableDictionary *subRoutes = [self addURLPattern:URLPattern]; if (handler && subRoutes) { subRoutes[@"_"] = [handler copy]; } } - (NSMutableDictionary *)addURLPattern:(NSString *)URLPattern { NSArray *pathComponents = [self pathComponentsFromURL:URLPattern]; NSInteger index = 0; NSMutableDictionary* subRoutes = self.routes; while (index < pathComponents.count) { NSString* pathComponent = pathComponents[index]; if (![subRoutes objectForKey:pathComponent]) { subRoutes[pathComponent] = [[NSMutableDictionary alloc] init]; } subRoutes = subRoutes[pathComponent]; index++; } return subRoutes; } #pragma mark - Utils - (NSMutableDictionary *)extractParametersFromURL:(NSString *)url { NSMutableDictionary* parameters = [NSMutableDictionary dictionary]; parameters[EcoRouterParameterURL] = url; NSMutableDictionary* subRoutes = self.routes; NSArray* pathComponents = [self pathComponentsFromURL:url]; BOOL found = NO; // borrowed from HHRouter(path_to_url for (NSString* pathComponent in pathComponents) { // key ~ NSArray *subRoutesKeys =[subRoutes.allKeys sortedArrayUsingComparator:^NSComparisonResult(NSString *obj1, NSString *obj2) { return [obj1 compare:obj2]; }]; for (NSString* key in subRoutesKeys) { if ([key isEqualToString:pathComponent] || [key isEqualToString:Eco_ROUTER_WILDCARD_CHARACTER]) { found = YES; subRoutes = subRoutes[key]; break; } else if ([key hasPrefix:@":"]) { found = YES; subRoutes = subRoutes[key]; NSString *newKey = [key substringFromIndex:1]; NSString *newPathComponent = pathComponent; // :id.html -> :id if ([self.class checkIfContainsSpecialCharacter:key]) { NSCharacterSet *specialCharacterSet = [NSCharacterSet characterSetWithCharactersInString:specialCharacters]; NSRange range = [key rangeOfCharacterFromSet:specialCharacterSet]; if (range.location != NSNotFound) { // pathComponent newKey = [newKey substringToIndex:range.location - 1]; NSString *suffixToStrip = [key substringFromIndex:range.location]; newPathComponent = [newPathComponent stringByReplacingOccurrencesOfString:suffixToStrip withString:@""]; } } parameters[newKey] = newPathComponent; break; } } // pathComponent handler handler fallback if (!found && !subRoutes[@"_"]) { return nil; } } // Extract Params From Query. NSArray* pathInfo = [url componentsSeparatedByString:@"?"]; if (pathInfo.count > 1) { NSString* parametersString = [pathInfo objectAtIndex:1]; NSArray* paramStringArr = [parametersString componentsSeparatedByString:@"&"]; for (NSString* paramString in paramStringArr) { NSArray* paramArr = [paramString componentsSeparatedByString:@"="]; if (paramArr.count > 1) { NSString* key = [paramArr objectAtIndex:0]; NSString* value = [paramArr objectAtIndex:1]; parameters[key] = value; } } } if (subRoutes[@"_"]) { parameters[@"block"] = [subRoutes[@"_"] copy]; } return parameters; } - (void)removeURLPattern:(NSString *)URLPattern { NSMutableArray *pathComponents = [NSMutableArray arrayWithArray:[self pathComponentsFromURL:URLPattern]]; // pattern if (pathComponents.count >= 1) { // URLPattern a/b/c, components @"a.b.c" KVC key NSString *components = [pathComponents componentsJoinedByString:@"."]; NSMutableDictionary *route = [self.routes valueForKeyPath:components]; if (route.count >= 1) { NSString *lastComponent = [pathComponents lastObject]; [pathComponents removeLastObject]; // key self.routes route = self.routes; if (pathComponents.count) { NSString *componentsWithoutLast = [pathComponents componentsJoinedByString:@"."]; route = [self.routes valueForKeyPath:componentsWithoutLast]; } [route removeObjectForKey:lastComponent]; } } } - (NSArray*)pathComponentsFromURL:(NSString*)URL { NSMutableArray *pathComponents = [NSMutableArray array]; if ([URL rangeOfString:@"://"].location != NSNotFound) { NSArray *pathSegments = [URL componentsSeparatedByString:@"://"]; // URL [pathComponents addObject:pathSegments[0]]; // if ((pathSegments.count >= 2 && ((NSString *)pathSegments[1]).length) || pathSegments.count < 2) { [pathComponents addObject:Eco_ROUTER_WILDCARD_CHARACTER]; } URL = [URL substringFromIndex:[URL rangeOfString:@"://"].location + 3]; } for (NSString *pathComponent in [[NSURL URLWithString:URL] pathComponents]) { if ([pathComponent isEqualToString:@"/"]) continue; if ([[pathComponent substringToIndex:1] isEqualToString:@"?"]) break; [pathComponents addObject:pathComponent]; } return [pathComponents copy]; } - (NSMutableDictionary *)routes { if (!_routes) { _routes = [[NSMutableDictionary alloc] init]; } return _routes; } #pragma mark - Utils + (BOOL)checkIfContainsSpecialCharacter:(NSString *)checkedString { NSCharacterSet *specialCharactersSet = [NSCharacterSet characterSetWithCharactersInString:specialCharacters]; return [checkedString rangeOfCharacterFromSet:specialCharactersSet].location != NSNotFound; } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Router/EcoRouterDemo/Router/EcoRouter.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
2,493
```objective-c // // EcoRouter.h // EcoRouterDemo // // Created by on 2017/3/5. // #import <Foundation/Foundation.h> extern NSString *const EcoRouterParameterURL; extern NSString *const EcoRouterParameterCompletion; extern NSString *const EcoRouterParameterUserInfo; /** * routerParameters string */ typedef void (^EcoRouterHandler)(NSDictionary *routerParameters); /** * object objectForURL: */ typedef id (^EcoRouterObjectHandler)(NSDictionary *routerParameters); @interface EcoRouter : NSObject /** * URLPattern Handler handler VC VC * * @param URLPattern scheme Eco://beauty/:id * @param handler block URL * URL Eco://beauty/:id @{@"id": 4} */ + (void)registerURLPattern:(NSString *)URLPattern toHandler:(EcoRouterHandler)handler; /** * URLPattern ObjectHandler object * * @param URLPattern scheme Eco://beauty/:id * @param handler block URL * URL Eco://beauty/:id @{@"id": 4} * key @"url" @"completion" () */ + (void)registerURLPattern:(NSString *)URLPattern toObjectHandler:(EcoRouterObjectHandler)handler; /** * URL Pattern * * @param URLPattern URL */ + (void)deregisterURLPattern:(NSString *)URLPattern; /** * URL * URL -> Handler Handler * * @param URL Scheme Eco://beauty/3 */ + (void)openURL:(NSString *)URL; /** * URL * * @param URL Scheme URL Eco://beauty/4 * @param completion URL callback */ + (void)openURL:(NSString *)URL completion:(void (^)(id result))completion; /** * URL * * @param URL Scheme URL Eco://beauty/4 * @param userInfo * @param completion URL callback */ + (void)openURL:(NSString *)URL withUserInfo:(NSDictionary *)userInfo completion:(void (^)(id result))completion; /** * URL object * * @param URL URL */ + (id)objectForURL:(NSString *)URL; /** * URL object * * @param URL URL * @param userInfo */ + (id)objectForURL:(NSString *)URL withUserInfo:(NSDictionary *)userInfo; /** * URL * * @param URL URL * * @return YES/NO */ + (BOOL)canOpenURL:(NSString *)URL; /** * urlpattern parameters * * #define Eco_ROUTE_BEAUTY @"beauty/:id" * [EcoRouter generateURLWithPattern:Eco_ROUTE_BEAUTY, @[@13]]; * * * @param pattern url pattern @"beauty/:id" * @param parameters pattern * * @return URL */ + (NSString *)generateURLWithPattern:(NSString *)pattern parameters:(NSArray *)parameters; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Router/EcoRouterDemo/Router/EcoRouter.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
672
```objective-c // // UIViewController+Router.h // EcoRouterDemo // // Created by on 2017/3/14. // #import <UIKit/UIKit.h> @interface UIViewController (Router) /** */ @property (nonatomic, strong) NSDictionary *paramDic; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Router/EcoRouterDemo/Router/Category/UIViewController+Router.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
58
```objective-c // // TestAViewController.m // RouterTest // // Created by on 2017/3/5. // #import "ModuleBViewController.h" #import "EcoRouterTool.h" @implementation ModuleBViewController - (void)viewDidLoad { [super viewDidLoad]; self.title = @"ModuleB_B"; // Do any additional setup after loading the view. } - (void)setNavBarItem { [self addRightItem]; } /// - (void)actionGo { [EcoRouterTool openClass:@"ModuleAViewController" withUserInfo:@{@"key1":@"1",@"key2":@"2"} from:self.navigationController]; } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Router/EcoRouterDemo/ModuleB/Controllers/ModuleBViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
141
```objective-c // // ModuleBViewController.h // RouterTest // // Created by on 2017/3/5. // #import "EcoBaseViewController.h" @interface ModuleBViewController : EcoBaseViewController @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Router/EcoRouterDemo/ModuleB/Controllers/ModuleBViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
49
```objective-c // // UIViewController+Router.m // EcoRouterDemo // // Created by on 2017/3/14. // #import "UIViewController+Router.h" #import <objc/runtime.h> static const void *ParamDicKey = &ParamDicKey; @implementation UIViewController (Router) - (void)setParamDic:(NSDictionary *)paramDic { objc_setAssociatedObject(self, ParamDicKey, paramDic, OBJC_ASSOCIATION_RETAIN_NONATOMIC); } - (NSDictionary *)paramDic { return objc_getAssociatedObject(self, ParamDicKey); } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Router/EcoRouterDemo/Router/Category/UIViewController+Router.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
124
```objective-c // // ModuleBRootViewController.h // EcoRouterDemo // // Created by on 2017/3/5. // #import "EcoBaseViewController.h" @interface ModuleBRootViewController : EcoBaseViewController @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Router/EcoRouterDemo/ModuleB/Controllers/ModuleBRootViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
52
```objective-c // // ModuleARootViewController.h // EcoRouterDemo // // Created by on 2017/3/5. // #import "EcoBaseViewController.h" @interface ModuleARootViewController : EcoBaseViewController @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Router/EcoRouterDemo/ModuleA/Controllers/ModuleARootViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
52
```objective-c // // ModuleBRootViewController.m // EcoRouterDemo // // Created by on 2017/3/5. // #import "ModuleBRootViewController.h" #import "EcoRouterTool.h" @interface ModuleBRootViewController () @end @implementation ModuleBRootViewController - (void)viewDidLoad { [super viewDidLoad]; self.title = @"ModuleB_Root"; // Do any additional setup after loading the view. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)actionGo { [EcoRouterTool openClass:@"ModuleBViewController" withUserInfo:nil from:self.navigationController]; } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Router/EcoRouterDemo/ModuleB/Controllers/ModuleBRootViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
211
```objective-c // // TestAViewController.h // RouterTest // // Created by on 2017/3/5. // #import "EcoBaseViewController.h" @interface ModuleAViewController : EcoBaseViewController @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Router/EcoRouterDemo/ModuleA/Controllers/ModuleAViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
49
```objective-c // // ModuleARootViewController.m // EcoRouterDemo // // Created by on 2017/3/5. // #import "ModuleARootViewController.h" #import "EcoRouterTool.h" @interface ModuleARootViewController () @end @implementation ModuleARootViewController - (void)viewDidLoad { [super viewDidLoad]; self.title = @"ModuleA_Root"; // Do any additional setup after loading the view. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /// - (void)actionGo { [EcoRouterTool openClass:@"ModuleAViewController" withUserInfo:nil from:self.navigationController]; } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Router/EcoRouterDemo/ModuleA/Controllers/ModuleARootViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
149
```objective-c // // TestAViewController.m // RouterTest // // Created by on 2017/3/5. // #import "ModuleAViewController.h" #import "EcoRouterTool.h" @implementation ModuleAViewController - (void)viewDidLoad { [super viewDidLoad]; self.title = @"ModuleA_A"; // Do any additional setup after loading the view. } - (void)setNavBarItem { [self addRightItem]; } /// - (void)actionGo { [EcoRouterTool openClass:@"ModuleBViewController" withUserInfo:nil from:self.navigationController]; } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Router/EcoRouterDemo/ModuleA/Controllers/ModuleAViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
130
```objective-c // // TwoViewController.m // JLRoutes // // Created by on 2017/3/27. // #import "TwoViewController.h" @interface TwoViewController () @end @implementation TwoViewController - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor redColor]; self.title = @""; UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; [btn setTitle:@"" forState:UIControlStateNormal]; [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; btn.titleLabel.font = [UIFont systemFontOfSize:16 weight:1]; btn.frame = CGRectMake(100, 200, 100, 100); [self.view addSubview:btn]; [btn addTarget:self action:@selector(jump) forControlEvents:UIControlEventTouchUpInside]; } - (void)jump { NSString *url = JLRoutesJumpUrl(@"JLRoutesTwo", @"OnePushViewController", @"123", nil, nil, nil); [[UIApplication sharedApplication]openURL:[NSURL URLWithString:url] options:nil completionHandler:nil]; } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Router/JLRouters/TwoViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
212
```objective-c // // OneViewController.h // JLRoutes // // Created by on 2017/3/27. // #import <UIKit/UIKit.h> @interface OneViewController : UIViewController @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Router/JLRouters/OneViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
44
```objective-c // // NavigationController.m // JLRoutes // // Created by on 2017/3/27. // #import "NavigationController.h" @interface NavigationController () @end @implementation NavigationController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Router/JLRouters/NavigationController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
156
```objective-c // // ThreePushViewController.h // JLRoutes // // Created by on 2017/3/27. // #import <UIKit/UIKit.h> @interface ThreePushViewController : UIViewController @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Router/JLRouters/ThreePushViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
46
```objective-c // // ThreePushViewController.m // JLRoutes // // Created by on 2017/3/27. // #import "ThreePushViewController.h" @interface ThreePushViewController () @end @implementation ThreePushViewController - (void)viewDidLoad { [super viewDidLoad]; self.title = @""; self.view.backgroundColor = [UIColor greenColor]; // Do any additional setup after loading the view. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Router/JLRouters/ThreePushViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
175
```objective-c // // OnePushViewController.m // JLRoutes // // Created by on 2017/3/27. // #import "OnePushViewController.h" @interface OnePushViewController () @end @implementation OnePushViewController - (void)viewDidLoad { [super viewDidLoad]; self.title = @""; self.view.backgroundColor = [UIColor purpleColor]; // Do any additional setup after loading the view. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Router/JLRouters/OnePushViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
175
```objective-c // // OnePushViewController.h // JLRoutes // // Created by on 2017/3/27. // #import <UIKit/UIKit.h> @interface OnePushViewController : UIViewController @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Router/JLRouters/OnePushViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
46
```objective-c // // TabbarController.m // JLRoutes // // Created by on 2017/3/27. // #import "JLRoutersTabbarController.h" #import "OneViewController.h" #import "TwoViewController.h" #import "ThreeViewController.h" #import "NavigationController.h" #import "OnePushViewController.h" #import "JLRoutes.h" @interface JLRoutersTabbarController () @end @implementation JLRoutersTabbarController - (void)viewDidLoad { [super viewDidLoad]; OneViewController *one = [[OneViewController alloc]init]; NavigationController *nav1 = [[NavigationController alloc]initWithRootViewController:one]; nav1.tabBarItem.title = @""; [self addChildViewController:nav1]; TwoViewController *two = [[TwoViewController alloc]init]; NavigationController *nav2 = [[NavigationController alloc]initWithRootViewController:two]; nav2.tabBarItem.title = @""; [self addChildViewController:nav2]; ThreeViewController *three = [[ThreeViewController alloc]init]; NavigationController *nav3 = [[NavigationController alloc]initWithRootViewController:three]; nav3.tabBarItem.title = @""; [self addChildViewController:nav3]; /* 1"info"-->"URL Types"URL Schemes, "JLRoutesOne, JLRoutesTwo, JLRoutesThree" 2AppDeleate */ [[JLRoutes globalRoutes]addRoute:@"/:toController/:paramOne/:paramTwo/:paramThree/:paramFour" handler:^BOOL(NSDictionary<NSString *,id> * _Nonnull parameters) { NSLog(@"parameters = %@", parameters); Class class = NSClassFromString(parameters[@"toController"]); UIViewController *vc = [[class alloc]init]; NSURL *headUrl = parameters[JLRouteURLKey]; NSString *head = [headUrl.absoluteString componentsSeparatedByString:@"://"].firstObject; if ([head isEqualToString:@"JLRoutesOne"]) { [nav1 pushViewController:vc animated:YES]; }else if ([head isEqualToString:@"JLRoutesTwo"]){ [nav2 pushViewController:vc animated:YES]; }else if([head isEqualToString:@"JLRoutesThree"]){ [nav3 pushViewController:vc animated:YES]; } return YES; }]; } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Router/JLRouters/JLRoutersTabbarController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
481
```objective-c // // TabbarController.h // JLRoutes // // Created by on 2017/3/27. // #import <UIKit/UIKit.h> @interface JLRoutersTabbarController : UITabBarController @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Router/JLRouters/JLRoutersTabbarController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
51
```objective-c // // TwoPushViewController.h // JLRoutes // // Created by on 2017/3/27. // #import <UIKit/UIKit.h> @interface TwoPushViewController : UIViewController @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Router/JLRouters/TwoPushViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
46
```objective-c // // TwoPushViewController.m // JLRoutes // // Created by on 2017/3/27. // #import "TwoPushViewController.h" @interface TwoPushViewController () @end @implementation TwoPushViewController - (void)viewDidLoad { [super viewDidLoad]; self.title = @""; self.view.backgroundColor = [UIColor grayColor]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Router/JLRouters/TwoPushViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
164
```objective-c // // TwoViewController.h // JLRoutes // // Created by on 2017/3/27. // #import <UIKit/UIKit.h> @interface TwoViewController : UIViewController @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Router/JLRouters/TwoViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
44
```objective-c // // OneViewController.m // JLRoutes // // Created by on 2017/3/27. // #import "OneViewController.h" @interface OneViewController () @end @implementation OneViewController - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor blueColor]; self.title = @""; UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; [btn setTitle:@"" forState:UIControlStateNormal]; [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; btn.titleLabel.font = [UIFont systemFontOfSize:16 weight:1]; btn.frame = CGRectMake(100, 200, 100, 100); [self.view addSubview:btn]; [btn addTarget:self action:@selector(jump) forControlEvents:UIControlEventTouchUpInside]; } - (void)jump { NSString *url = JLRoutesJumpUrl(@"JLRoutesOne", @"OnePushViewController", @"123", nil, nil, nil); [[UIApplication sharedApplication]openURL:[NSURL URLWithString:url] options:nil completionHandler:nil]; } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Router/JLRouters/OneViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
212
```objective-c // // NavigationController.h // JLRoutes // // Created by on 2017/3/27. // #import <UIKit/UIKit.h> @interface NavigationController : UINavigationController @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Router/JLRouters/NavigationController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
44
```objective-c // // ThreeViewController.m // JLRoutes // // Created by on 2017/3/27. // #import "ThreeViewController.h" @interface ThreeViewController () @end @implementation ThreeViewController - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor yellowColor]; self.title = @""; UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; [btn setTitle:@"" forState:UIControlStateNormal]; [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; btn.titleLabel.font = [UIFont systemFontOfSize:16 weight:1]; btn.frame = CGRectMake(100, 200, 100, 100); [self.view addSubview:btn]; [btn addTarget:self action:@selector(jump) forControlEvents:UIControlEventTouchUpInside]; } - (void)jump { NSString *url = JLRoutesJumpUrl(@"JLRoutesThree", @"OnePushViewController", @"123", nil, nil, nil); [[UIApplication sharedApplication]openURL:[NSURL URLWithString:url] options:nil completionHandler:nil]; } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Router/JLRouters/ThreeViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
212
```objective-c // // ThreeViewController.h // JLRoutes // // Created by on 2017/3/27. // #import <UIKit/UIKit.h> @interface ThreeViewController : UIViewController @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Router/JLRouters/ThreeViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
44
```objective-c /* All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of JLRoutes nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #import "JLRRouteDefinition.h" #import "JLRoutes.h" @interface JLRRouteDefinition () @property (nonatomic, strong) NSString *pattern; @property (nonatomic, strong) NSString *scheme; @property (nonatomic, assign) NSUInteger priority; @property (nonatomic, strong) BOOL (^handlerBlock)(NSDictionary *parameters); @property (nonatomic, strong) NSArray *patternComponents; @end @implementation JLRRouteDefinition - (instancetype)initWithScheme:(NSString *)scheme pattern:(NSString *)pattern priority:(NSUInteger)priority handlerBlock:(BOOL (^)(NSDictionary *parameters))handlerBlock { if ((self = [super init])) { self.scheme = scheme; self.pattern = pattern; self.priority = priority; self.handlerBlock = handlerBlock; if ([pattern characterAtIndex:0] == '/') { pattern = [pattern substringFromIndex:1]; } self.patternComponents = [pattern componentsSeparatedByString:@"/"]; } return self; } - (NSString *)description { return [NSString stringWithFormat:@"<%@ %p> - %@ (priority: %@)", NSStringFromClass([self class]), self, self.pattern, @(self.priority)]; } - (JLRRouteResponse *)routeResponseForRequest:(JLRRouteRequest *)request decodePlusSymbols:(BOOL)decodePlusSymbols { BOOL patternContainsWildcard = [self.patternComponents containsObject:@"*"]; if (request.pathComponents.count != self.patternComponents.count && !patternContainsWildcard) { // definitely not a match, nothing left to do return [JLRRouteResponse invalidMatchResponse]; } JLRRouteResponse *response = [JLRRouteResponse invalidMatchResponse]; NSMutableDictionary *routeParams = [NSMutableDictionary dictionary]; BOOL isMatch = YES; NSUInteger index = 0; for (NSString *patternComponent in self.patternComponents) { NSString *URLComponent = nil; // figure out which URLComponent it is, taking wildcards into account if (index < [request.pathComponents count]) { URLComponent = request.pathComponents[index]; } else if ([patternComponent isEqualToString:@"*"]) { // match /foo by /foo/* URLComponent = [request.pathComponents lastObject]; } if ([patternComponent hasPrefix:@":"]) { // this is a variable, set it in the params NSString *variableName = [self variableNameForValue:patternComponent]; NSString *variableValue = [self variableValueForValue:URLComponent decodePlusSymbols:decodePlusSymbols]; routeParams[variableName] = variableValue; } else if ([patternComponent isEqualToString:@"*"]) { // match wildcards NSUInteger minRequiredParams = index; if (request.pathComponents.count >= minRequiredParams) { // match: /a/b/c/* has to be matched by at least /a/b/c routeParams[JLRouteWildcardComponentsKey] = [request.pathComponents subarrayWithRange:NSMakeRange(index, request.pathComponents.count - index)]; isMatch = YES; } else { // not a match: /a/b/c/* cannot be matched by URL /a/b/ isMatch = NO; } break; } else if (![patternComponent isEqualToString:URLComponent]) { // break if this is a static component and it isn't a match isMatch = NO; break; } index++; } if (isMatch) { // if it's a match, set up the param dictionary and create a valid match response NSMutableDictionary *params = [NSMutableDictionary dictionary]; [params addEntriesFromDictionary:[request queryParamsDecodingPlusSymbols:decodePlusSymbols]]; [params addEntriesFromDictionary:routeParams]; [params addEntriesFromDictionary:[self baseMatchParametersForRequest:request]]; response = [JLRRouteResponse validMatchResponseWithParameters:[params copy]]; } return response; } - (NSString *)variableNameForValue:(NSString *)value { NSString *name = [value substringFromIndex:1]; if (name.length > 1 && [name characterAtIndex:0] == ':') { name = [name substringFromIndex:1]; } if (name.length > 1 && [name characterAtIndex:name.length - 1] == '#') { name = [name substringToIndex:name.length - 1]; } return name; } - (NSString *)variableValueForValue:(NSString *)value decodePlusSymbols:(BOOL)decodePlusSymbols { NSString *var = [value stringByRemovingPercentEncoding]; if (var.length > 1 && [var characterAtIndex:var.length - 1] == '#') { var = [var substringToIndex:var.length - 1]; } var = [JLRRouteRequest variableValueFrom:var decodePlusSymbols:decodePlusSymbols]; return var; } - (NSDictionary *)baseMatchParametersForRequest:(JLRRouteRequest *)request { return @{JLRoutePatternKey: self.pattern ?: [NSNull null], JLRouteURLKey: request.URL ?: [NSNull null], JLRouteSchemeKey: self.scheme ?: [NSNull null]}; } - (BOOL)callHandlerBlockWithParameters:(NSDictionary *)parameters { if (self.handlerBlock == nil) { return YES; } return self.handlerBlock(parameters); } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Router/JLRouters/Classes/JLRRouteDefinition.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
1,394
```objective-c /* All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of JLRoutes nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #import "JLRoutes.h" #import "JLRRouteDefinition.h" #import "JLROptionalRouteParser.h" NSString *const JLRoutePatternKey = @"JLRoutePattern"; NSString *const JLRouteURLKey = @"JLRouteURL"; NSString *const JLRouteSchemeKey = @"JLRouteScheme"; NSString *const JLRouteWildcardComponentsKey = @"JLRouteWildcardComponents"; NSString *const JLRoutesGlobalRoutesScheme = @"JLRoutesGlobalRoutesScheme"; static NSMutableDictionary *routeControllersMap = nil; static BOOL verboseLoggingEnabled = NO; static BOOL shouldDecodePlusSymbols = YES; @interface JLRoutes () @property (nonatomic, strong) NSMutableArray *routes; @property (nonatomic, strong) NSString *scheme; @end #pragma mark - @implementation JLRoutes - (instancetype)init { if ((self = [super init])) { self.routes = [NSMutableArray array]; } return self; } - (NSString *)description { return [self.routes description]; } + (NSString *)allRoutes { NSMutableString *descriptionString = [NSMutableString stringWithString:@"\n"]; for (NSString *routesNamespace in routeControllersMap) { JLRoutes *routesController = routeControllersMap[routesNamespace]; [descriptionString appendFormat:@"\"%@\":\n%@\n\n", routesController.scheme, routesController.routes]; } return descriptionString; } #pragma mark - Routing Schemes + (instancetype)globalRoutes { return [self routesForScheme:JLRoutesGlobalRoutesScheme]; } + (instancetype)routesForScheme:(NSString *)scheme { JLRoutes *routesController = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ routeControllersMap = [[NSMutableDictionary alloc] init]; }); if (!routeControllersMap[scheme]) { routesController = [[self alloc] init]; routesController.scheme = scheme; routeControllersMap[scheme] = routesController; } routesController = routeControllersMap[scheme]; return routesController; } + (void)unregisterRouteScheme:(NSString *)scheme { [routeControllersMap removeObjectForKey:scheme]; } + (void)unregisterAllRouteSchemes { [routeControllersMap removeAllObjects]; } #pragma mark - Registering Routes - (void)addRoute:(NSString *)routePattern handler:(BOOL (^)(NSDictionary<NSString *, id> *parameters))handlerBlock { [self addRoute:routePattern priority:0 handler:handlerBlock]; } - (void)addRoutes:(NSArray<NSString *> *)routePatterns handler:(BOOL (^)(NSDictionary<NSString *, id> *parameters))handlerBlock { for (NSString *routePattern in routePatterns) { [self addRoute:routePattern handler:handlerBlock]; } } - (void)addRoute:(NSString *)routePattern priority:(NSUInteger)priority handler:(BOOL (^)(NSDictionary<NSString *, id> *parameters))handlerBlock { NSArray <NSString *> *optionalRoutePatterns = [JLROptionalRouteParser expandOptionalRoutePatternsForPattern:routePattern]; if (optionalRoutePatterns.count > 0) { // there are optional params, parse and add them for (NSString *route in optionalRoutePatterns) { [self _verboseLog:@"Automatically created optional route: %@", route]; [self _registerRoute:route priority:priority handler:handlerBlock]; } return; } [self _registerRoute:routePattern priority:priority handler:handlerBlock]; } - (void)removeRoute:(NSString *)routePattern { if (![routePattern hasPrefix:@"/"]) { routePattern = [NSString stringWithFormat:@"/%@", routePattern]; } NSInteger routeIndex = NSNotFound; NSInteger index = 0; for (JLRRouteDefinition *route in [self.routes copy]) { if ([route.pattern isEqualToString:routePattern]) { routeIndex = index; break; } index++; } if (routeIndex != NSNotFound) { [self.routes removeObjectAtIndex:(NSUInteger)routeIndex]; } } - (void)removeAllRoutes { [self.routes removeAllObjects]; } - (void)setObject:(id)handlerBlock forKeyedSubscript:(NSString *)routePatten { [self addRoute:routePatten handler:handlerBlock]; } #pragma mark - Routing URLs + (BOOL)canRouteURL:(NSURL *)URL { return [[self _routesControllerForURL:URL] canRouteURL:URL]; } - (BOOL)canRouteURL:(NSURL *)URL { return [self _routeURL:URL withParameters:nil executeRouteBlock:NO]; } + (BOOL)routeURL:(NSURL *)URL { return [[self _routesControllerForURL:URL] routeURL:URL]; } - (BOOL)routeURL:(NSURL *)URL { return [self _routeURL:URL withParameters:nil executeRouteBlock:YES]; } + (BOOL)routeURL:(NSURL *)URL withParameters:(NSDictionary *)parameters { return [[self _routesControllerForURL:URL] routeURL:URL withParameters:parameters]; } - (BOOL)routeURL:(NSURL *)URL withParameters:(NSDictionary *)parameters { return [self _routeURL:URL withParameters:parameters executeRouteBlock:YES]; } #pragma mark - Private + (instancetype)_routesControllerForURL:(NSURL *)URL { if (URL == nil) { return nil; } return routeControllersMap[URL.scheme] ?: [JLRoutes globalRoutes]; } - (void)_registerRoute:(NSString *)routePattern priority:(NSUInteger)priority handler:(BOOL (^)(NSDictionary *parameters))handlerBlock { JLRRouteDefinition *route = [[JLRRouteDefinition alloc] initWithScheme:self.scheme pattern:routePattern priority:priority handlerBlock:handlerBlock]; if (priority == 0 || self.routes.count == 0) { [self.routes addObject:route]; } else { NSUInteger index = 0; BOOL addedRoute = NO; // search through existing routes looking for a lower priority route than this one for (JLRRouteDefinition *existingRoute in [self.routes copy]) { if (existingRoute.priority < priority) { // if found, add the route after it [self.routes insertObject:route atIndex:index]; addedRoute = YES; break; } index++; } // if we weren't able to find a lower priority route, this is the new lowest priority route (or same priority as self.routes.lastObject) and should just be added if (!addedRoute) { [self.routes addObject:route]; } } } - (BOOL)_routeURL:(NSURL *)URL withParameters:(NSDictionary *)parameters executeRouteBlock:(BOOL)executeRouteBlock { if (!URL) { return NO; } [self _verboseLog:@"Trying to route URL %@", URL]; BOOL didRoute = NO; JLRRouteRequest *request = [[JLRRouteRequest alloc] initWithURL:URL]; for (JLRRouteDefinition *route in [self.routes copy]) { // check each route for a matching response JLRRouteResponse *response = [route routeResponseForRequest:request decodePlusSymbols:shouldDecodePlusSymbols]; if (!response.isMatch) { continue; } [self _verboseLog:@"Successfully matched %@", route]; if (!executeRouteBlock) { // if we shouldn't execute but it was a match, we're done now return YES; } // configure the final parameters NSMutableDictionary *finalParameters = [NSMutableDictionary dictionary]; [finalParameters addEntriesFromDictionary:response.parameters]; [finalParameters addEntriesFromDictionary:parameters]; [self _verboseLog:@"Final parameters are %@", finalParameters]; didRoute = [route callHandlerBlockWithParameters:finalParameters]; if (didRoute) { // if it was routed successfully, we're done break; } } if (!didRoute) { [self _verboseLog:@"Could not find a matching route"]; } // if we couldn't find a match and this routes controller specifies to fallback and its also not the global routes controller, then... if (!didRoute && self.shouldFallbackToGlobalRoutes && ![self _isGlobalRoutesController]) { [self _verboseLog:@"Falling back to global routes..."]; didRoute = [[JLRoutes globalRoutes] _routeURL:URL withParameters:parameters executeRouteBlock:executeRouteBlock]; } // if, after everything, we did not route anything and we have an unmatched URL handler, then call it if (!didRoute && executeRouteBlock && self.unmatchedURLHandler) { [self _verboseLog:@"Falling back to the unmatched URL handler"]; self.unmatchedURLHandler(self, URL, parameters); } return didRoute; } - (BOOL)_isGlobalRoutesController { return [self.scheme isEqualToString:JLRoutesGlobalRoutesScheme]; } - (void)_verboseLog:(NSString *)format, ... { if (!verboseLoggingEnabled || format.length == 0) { return; } va_list argsList; va_start(argsList, format); #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wformat-nonliteral" NSString *formattedLogMessage = [[NSString alloc] initWithFormat:format arguments:argsList]; #pragma clang diagnostic pop va_end(argsList); NSLog(@"[JLRoutes]: %@", formattedLogMessage); } @end #pragma mark - Global Options @implementation JLRoutes (GlobalOptions) + (void)setVerboseLoggingEnabled:(BOOL)loggingEnabled { verboseLoggingEnabled = loggingEnabled; } + (BOOL)isVerboseLoggingEnabled { return verboseLoggingEnabled; } + (void)setShouldDecodePlusSymbols:(BOOL)shouldDecode { shouldDecodePlusSymbols = shouldDecode; } + (BOOL)shouldDecodePlusSymbols { return shouldDecodePlusSymbols; } @end #pragma mark - Deprecated // deprecated NSString *const kJLRoutePatternKey = @"JLRoutePattern"; NSString *const kJLRouteURLKey = @"JLRouteURL"; NSString *const kJLRouteSchemeKey = @"JLRouteScheme"; NSString *const kJLRouteWildcardComponentsKey = @"JLRouteWildcardComponents"; NSString *const kJLRoutesGlobalRoutesScheme = @"JLRoutesGlobalRoutesScheme"; NSString *const kJLRouteNamespaceKey = @"JLRouteScheme"; // deprecated NSString *const kJLRoutesGlobalNamespaceKey = @"JLRoutesGlobalRoutesScheme"; // deprecated @implementation JLRoutes (Deprecated) + (void)addRoute:(NSString *)routePattern handler:(BOOL (^)(NSDictionary<NSString *, id> *parameters))handlerBlock { [[self globalRoutes] addRoute:routePattern handler:handlerBlock]; } + (void)addRoute:(NSString *)routePattern priority:(NSUInteger)priority handler:(BOOL (^)(NSDictionary<NSString *, id> *parameters))handlerBlock { [[self globalRoutes] addRoute:routePattern priority:priority handler:handlerBlock]; } + (void)addRoutes:(NSArray<NSString *> *)routePatterns handler:(BOOL (^)(NSDictionary<NSString *, id> *parameters))handlerBlock { [[self globalRoutes] addRoutes:routePatterns handler:handlerBlock]; } + (void)removeRoute:(NSString *)routePattern { [[self globalRoutes] removeRoute:routePattern]; } + (void)removeAllRoutes { [[self globalRoutes] removeAllRoutes]; } + (BOOL)canRouteURL:(NSURL *)URL withParameters:(NSDictionary *)parameters { return [[self globalRoutes] canRouteURL:URL]; } - (BOOL)canRouteURL:(NSURL *)URL withParameters:(NSDictionary *)parameters { return [self canRouteURL:URL]; } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Router/JLRouters/Classes/JLRoutes.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
2,805
```objective-c /* All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of JLRoutes nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #import "JLRRouteRequest.h" @interface JLRRouteRequest () @property (nonatomic, strong) NSURL *URL; @property (nonatomic, strong) NSArray *pathComponents; @property (nonatomic, strong) NSDictionary *queryParams; @end @implementation JLRRouteRequest - (instancetype)initWithURL:(NSURL *)URL { if ((self = [super init])) { self.URL = URL; NSURLComponents *components = [NSURLComponents componentsWithString:[self.URL absoluteString]]; if (components.host.length > 0 && ![components.host isEqualToString:@"localhost"]) { // convert the host to "/" so that the host is considered a path component NSString *host = [components.percentEncodedHost copy]; components.host = @"/"; components.percentEncodedPath = [host stringByAppendingPathComponent:(components.percentEncodedPath ?: @"")]; } NSString *path = [components percentEncodedPath]; // handle fragment if needed if (components.fragment != nil) { BOOL fragmentContainsQueryParams = NO; NSURLComponents *fragmentComponents = [NSURLComponents componentsWithString:components.percentEncodedFragment]; if (fragmentComponents.query == nil && fragmentComponents.path != nil) { fragmentComponents.query = fragmentComponents.path; } if (fragmentComponents.queryItems.count > 0) { // determine if this fragment is only valid query params and nothing else fragmentContainsQueryParams = fragmentComponents.queryItems.firstObject.value.length > 0; } if (fragmentContainsQueryParams) { // include fragment query params in with the standard set components.queryItems = [(components.queryItems ?: @[]) arrayByAddingObjectsFromArray:fragmentComponents.queryItems]; } if (fragmentComponents.path != nil && (!fragmentContainsQueryParams || ![fragmentComponents.path isEqualToString:fragmentComponents.query])) { // handle fragment by include fragment path as part of the main path path = [path stringByAppendingString:[NSString stringWithFormat:@"#%@", fragmentComponents.percentEncodedPath]]; } } // strip off leading slash so that we don't have an empty first path component if (path.length > 0 && [path characterAtIndex:0] == '/') { path = [path substringFromIndex:1]; } // strip off trailing slash for the same reason if (path.length > 0 && [path characterAtIndex:path.length - 1] == '/') { path = [path substringToIndex:path.length - 1]; } // split apart into path components self.pathComponents = [path componentsSeparatedByString:@"/"]; // convert query items into a dictionary NSArray <NSURLQueryItem *> *queryItems = [components queryItems] ?: @[]; NSMutableDictionary *queryParams = [NSMutableDictionary dictionary]; for (NSURLQueryItem *item in queryItems) { if (item.value == nil) { continue; } if (queryParams[item.name] == nil) { // first time seeing a param with this name, set it queryParams[item.name] = item.value; } else if ([queryParams[item.name] isKindOfClass:[NSArray class]]) { // already an array of these items, append it NSArray *values = (NSArray *)(queryParams[item.name]); queryParams[item.name] = [values arrayByAddingObject:item.value]; } else { // existing non-array value for this key, create an array id existingValue = queryParams[item.name]; queryParams[item.name] = @[existingValue, item.value]; } } self.queryParams = [queryParams copy]; } return self; } + (NSString *)variableValueFrom:(NSString *)value decodePlusSymbols:(BOOL)decodePlusSymbols; { if (!decodePlusSymbols) { return value; } return [value stringByReplacingOccurrencesOfString:@"+" withString:@" " options:NSLiteralSearch range:NSMakeRange(0, value.length)]; } - (NSDictionary *)queryParamsDecodingPlusSymbols:(BOOL)decodePlusSymbols; { if (!decodePlusSymbols) { return self.queryParams; } NSMutableDictionary *updatedQueryParams = [NSMutableDictionary dictionary]; for (NSString *name in self.queryParams) { id value = self.queryParams[name]; if ([value isKindOfClass:[NSArray class]]) { NSMutableArray *variables = [NSMutableArray array]; for (NSString *arrayValue in (NSArray *)value) { [variables addObject:[[self class] variableValueFrom:arrayValue decodePlusSymbols:decodePlusSymbols]]; } updatedQueryParams[name] = [variables copy]; } else if ([value isKindOfClass:[NSString class]]) { NSString *variable = [[self class] variableValueFrom:value decodePlusSymbols:decodePlusSymbols]; updatedQueryParams[name] = variable; } else { // NSAssert(NO, @"Unexpected query parameter type: %@", NSStringFromClass([value class])); } } return [updatedQueryParams copy]; } - (NSString *)description { return [NSString stringWithFormat:@"<%@ %p> - URL: %@", NSStringFromClass([self class]), self, [self.URL absoluteString]]; } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Router/JLRouters/Classes/JLRRouteRequest.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
1,327
```objective-c /* All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of JLRoutes nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #import <Foundation/Foundation.h> #import "JLRRouteRequest.h" #import "JLRRouteResponse.h" NS_ASSUME_NONNULL_BEGIN @interface JLRRouteDefinition : NSObject @property (nonatomic, strong, readonly) NSString *scheme; @property (nonatomic, strong, readonly) NSString *pattern; @property (nonatomic, assign, readonly) NSUInteger priority; - (instancetype)initWithScheme:(NSString *)scheme pattern:(NSString *)pattern priority:(NSUInteger)priority handlerBlock:(BOOL (^)(NSDictionary *parameters))handlerBlock; - (JLRRouteResponse *)routeResponseForRequest:(JLRRouteRequest *)request decodePlusSymbols:(BOOL)decodePlusSymbols; - (BOOL)callHandlerBlockWithParameters:(NSDictionary *)parameters; @end NS_ASSUME_NONNULL_END ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Router/JLRouters/Classes/JLRRouteDefinition.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
407
```objective-c /* All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of JLRoutes nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #import "JLRRouteResponse.h" @interface JLRRouteResponse () @property (nonatomic, assign, getter=isMatch) BOOL match; @property (nonatomic, strong) NSDictionary *parameters; @end @implementation JLRRouteResponse + (instancetype)invalidMatchResponse { JLRRouteResponse *response = [[[self class] alloc] init]; response.match = NO; return response; } + (instancetype)validMatchResponseWithParameters:(NSDictionary *)parameters { JLRRouteResponse *response = [[[self class] alloc] init]; response.match = YES; response.parameters = parameters; return response; } - (NSString *)description { return [NSString stringWithFormat:@"<%@ %p> - match: %@, params: %@", NSStringFromClass([self class]), self, (self.match ? @"YES" : @"NO"), self.parameters]; } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Router/JLRouters/Classes/JLRRouteResponse.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
436
```objective-c /* All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of JLRoutes nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #import <Foundation/Foundation.h> NS_ASSUME_NONNULL_BEGIN @interface JLRRouteRequest : NSObject @property (nonatomic, strong, readonly) NSURL *URL; @property (nonatomic, strong, readonly) NSArray *pathComponents; @property (nonatomic, strong, readonly) NSDictionary *queryParams; - (instancetype)initWithURL:(NSURL *)URL; + (NSString *)variableValueFrom:(NSString *)value decodePlusSymbols:(BOOL)decodePlusSymbols; - (NSDictionary *)queryParamsDecodingPlusSymbols:(BOOL)decodePlusSymbols; @end NS_ASSUME_NONNULL_END ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Router/JLRouters/Classes/JLRRouteRequest.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
367
```objective-c /* All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of JLRoutes nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #import <Foundation/Foundation.h> NS_ASSUME_NONNULL_BEGIN @interface JLROptionalRouteParser : NSObject + (NSArray <NSString *> *)expandOptionalRoutePatternsForPattern:(NSString *)routePattern; @end NS_ASSUME_NONNULL_END ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Router/JLRouters/Classes/JLROptionalRouteParser.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
304
```objective-c /* All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of JLRoutes nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #import "JLROptionalRouteParser.h" @interface NSArray (Combinations) - (NSArray<NSArray *> *)JLRoutes_allOrderedCombinations; @end @implementation JLROptionalRouteParser + (NSArray <NSString *> *)expandOptionalRoutePatternsForPattern:(NSString *)routePattern { /* this method exists to take a route pattern that is known to contain optional params, such as: /path/:thing/(/a)(/b)(/c) and create the following paths: /path/:thing/a/b/c /path/:thing/a/b /path/:thing/a/c /path/:thing/b/a /path/:thing/a /path/:thing/b /path/:thing/c */ if ([routePattern rangeOfString:@"("].location == NSNotFound) { return @[]; } NSString *baseRoute = nil; NSArray *components = [self _optionalComponentsForPattern:routePattern baseRoute:&baseRoute]; NSArray *routes = [self _routesForOptionalComponents:components baseRoute:baseRoute]; return routes; } + (NSArray <NSString *> *)_optionalComponentsForPattern:(NSString *)routePattern baseRoute:(NSString **)outBaseRoute; { if (routePattern.length == 0) { return @[]; } NSMutableArray *optionalComponents = [NSMutableArray array]; NSScanner *scanner = [NSScanner scannerWithString:routePattern]; NSString *nonOptionalRouteSubpath = nil; BOOL parsedBaseRoute = NO; BOOL parseError = NO; // first, we need to parse the string and find the array of optional params. // aka, take (/a)(/b)(/c) and turn it into ["/a", "/b", "/c"] while ([scanner scanUpToString:@"(" intoString:&nonOptionalRouteSubpath]) { if ([scanner isAtEnd]) { break; } if (nonOptionalRouteSubpath.length > 0 && outBaseRoute != NULL && !parsedBaseRoute) { // the first 'non optional subpath' is always the base route *outBaseRoute = nonOptionalRouteSubpath; parsedBaseRoute = YES; } scanner.scanLocation = scanner.scanLocation + 1; NSString *component = nil; if (![scanner scanUpToString:@")" intoString:&component]) { parseError = YES; break; } [optionalComponents addObject:component]; } if (parseError) { NSLog(@"[JLRoutes]: Parse error, unsupported route: %@", routePattern); return @[]; } return [optionalComponents copy]; } + (NSArray <NSString *> *)_routesForOptionalComponents:(NSArray <NSString *> *)optionalComponents baseRoute:(NSString *)baseRoute { if (optionalComponents.count == 0 || baseRoute.length == 0) { return @[]; } NSMutableArray *routes = [NSMutableArray array]; // generate all possible combinations of the components that could exist (taking order into account) // aka, "/path/:thing/(/a)(/b)(/c)" should never generate a route for "/path/:thing/(/b)(/a)" NSArray *combinations = [optionalComponents JLRoutes_allOrderedCombinations]; // generate the actual final route path strings for (NSArray *components in combinations) { NSString *path = [components componentsJoinedByString:@""]; [routes addObject:[baseRoute stringByAppendingString:path]]; } // sort them so that the longest routes are first (since they are the most selective) [routes sortUsingSelector:@selector(length)]; return [routes copy]; } @end @implementation NSArray (JLRoutes) - (NSArray<NSArray *> *)JLRoutes_allOrderedCombinations { NSInteger length = self.count; if (length == 0) { return [NSArray arrayWithObject:[NSArray array]]; } id lastObject = [self lastObject]; NSArray *subarray = [self subarrayWithRange:NSMakeRange(0, length - 1)]; NSArray *subarrayCombinations = [subarray JLRoutes_allOrderedCombinations]; NSMutableArray *combinations = [NSMutableArray arrayWithArray:subarrayCombinations]; for (NSArray *subarrayCombos in subarrayCombinations) { [combinations addObject:[subarrayCombos arrayByAddingObject:lastObject]]; } return [NSArray arrayWithArray:combinations]; } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Router/JLRouters/Classes/JLROptionalRouteParser.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
1,231
```objective-c /* All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of JLRoutes nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #import <Foundation/Foundation.h> NS_ASSUME_NONNULL_BEGIN @interface JLRRouteResponse : NSObject @property (nonatomic, assign, readonly, getter=isMatch) BOOL match; @property (nonatomic, strong, readonly, nullable) NSDictionary *parameters; + (instancetype)invalidMatchResponse; + (instancetype)validMatchResponseWithParameters:(NSDictionary *)parameters; @end NS_ASSUME_NONNULL_END ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Router/JLRouters/Classes/JLRRouteResponse.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
334
```objective-c // // YFVIPERViewController.m // BigShow1949 // // Created by big show on 2018/10/15. // #import "YFVIPERViewController.h" @interface YFVIPERViewController () @end @implementation YFVIPERViewController - (void)viewDidLoad { [super viewDidLoad]; [self setupDataArr:@[@[@"Counter",@"YFCounterViewController_UIStoryboard"], @[@"TableList",@"YFViperTableListViewController"], @[@"ToDo",@"YFToDoBaseViewController"], @[@"Note",@"YFNoteListViperViewController"] // ]]; } /* V LoginView UILabelUIButton P iOS OS X (I) PONSO UI (E) (R) VIPER UIWindowUINavigationController UIViewController / */ @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/YFVIPERViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
180
```objective-c // // YFVIPERViewController.h // BigShow1949 // // Created by big show on 2018/10/15. // #import "BaseTableViewController.h" @interface YFVIPERViewController : BaseTableViewController @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/YFVIPERViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
55
```objective-c // // YFCounterInteractorIO.h // BigShow1949 // // Created by big show on 2018/10/15. // #ifndef YFCounterInteractorIO_h #define YFCounterInteractorIO_h @protocol YFCounterInteractorInput <NSObject> - (void)requestCount; - (void)increment; - (void)decrement; @end @protocol YFCounterInteractorOutput <NSObject> - (void)updateCount:(NSUInteger)count; @end #endif /* YFCounterInteractorIO_h */ ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Counter/YFCounterInteractorIO.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
119
```objective-c // // YFETtstViewController.h // BigShow1949 // // Created by big show on 2018/10/15. // #import <UIKit/UIKit.h> @class YFCounterPresenter; @interface YFCounterViewController : UIViewController @property (weak, nonatomic) IBOutlet UILabel *countLabel; @property (weak, nonatomic) IBOutlet UIButton *decrementButton; @property (weak, nonatomic) IBOutlet UIButton *incrementButton; @property (nonatomic, strong) YFCounterPresenter *presenter; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Counter/YFCounterViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
109
```objective-c // // YFCounterPresenter.m // BigShow1949 // // Created by big show on 2018/10/15. // #import "YFCounterPresenter.h" @implementation YFCounterPresenter #pragma mark - Public - (void)updateView { [self.delegateInteractor requestCount]; } - (void)increment { [self.delegateInteractor increment]; } - (void)decrement { [self.delegateInteractor decrement]; } #pragma mark - YFCounterInteractorOutput - (void)updateCount:(NSUInteger)count { [self.delegateView setCountText:[NSString stringWithFormat:@"%lu",(unsigned long)count]]; [self.delegateView setDecrementEnabled:[self canDecrementCount:count]]; } - (BOOL)canDecrementCount:(NSUInteger)count { return (count > 0); } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Counter/YFCounterPresenter.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
185
```objective-c // // YFETtstViewController.m // BigShow1949 // // Created by big show on 2018/10/15. // #import "YFCounterViewController.h" #import "YFCounterPresenter.h" #import "YFCounterInteractor.h" @interface YFCounterViewController ()<YFCounterView> @end @implementation YFCounterViewController - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor whiteColor]; self.countLabel.text = nil; // YFCounterPresenter *presenter = [[YFCounterPresenter alloc] init]; self.presenter = presenter; presenter.delegateView = self; // self-----strong-presenter-----weak-delegateView----self // presenter----strong-interactor----weak-presenter YFCounterInteractor *interactor = [[YFCounterInteractor alloc] init]; presenter.delegateInteractor = interactor; // delegateInteractorstronginteractor interactor.output = presenter; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self.presenter updateView]; } - (IBAction)decrement:(id)sender { [self.presenter decrement]; } - (IBAction)increment:(id)sender { [self.presenter increment]; } #pragma mark - Count view - (void)setCountText:(NSString *)countText { self.countLabel.text = countText; } - (void)setDecrementEnabled:(BOOL)enabled { self.decrementButton.enabled = enabled; } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Counter/YFCounterViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
323
```objective-c /* All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of JLRoutes nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #import <Foundation/Foundation.h> NS_ASSUME_NONNULL_BEGIN extern NSString *const JLRoutePatternKey; extern NSString *const JLRouteURLKey; extern NSString *const JLRouteSchemeKey; extern NSString *const JLRouteWildcardComponentsKey; extern NSString *const JLRoutesGlobalRoutesScheme; @interface JLRoutes : NSObject /// Controls whether or not this router will try to match a URL with global routes if it can't be matched in the current namespace. Default is NO. @property (nonatomic, assign) BOOL shouldFallbackToGlobalRoutes; /// Called any time routeURL returns NO. Respects shouldFallbackToGlobalRoutes. @property (nonatomic, copy) void (^__nullable unmatchedURLHandler)(JLRoutes *routes, NSURL *__nullable URL, NSDictionary<NSString *, id> *__nullable parameters); #pragma mark - Routing Schemes /// Returns the global routing scheme (this is used by the +addRoute methods by default) + (instancetype)globalRoutes; /// Returns a routing namespace for the given scheme + (instancetype)routesForScheme:(NSString *)scheme; /// Unregister and delete an entire scheme namespace + (void)unregisterRouteScheme:(NSString *)scheme; /// Unregister all routes + (void)unregisterAllRouteSchemes; #pragma mark - Registering Routes /// Registers a routePattern with default priority (0) in the receiving scheme namespace. - (void)addRoute:(NSString *)routePattern handler:(BOOL (^__nullable)(NSDictionary<NSString *, id> *parameters))handlerBlock; /// Registers a routePattern in the global scheme namespace with a handlerBlock to call when the route pattern is matched by a URL. /// The block returns a BOOL representing if the handlerBlock actually handled the route or not. If /// a block returns NO, JLRoutes will continue trying to find a matching route. - (void)addRoute:(NSString *)routePattern priority:(NSUInteger)priority handler:(BOOL (^__nullable)(NSDictionary<NSString *, id> *parameters))handlerBlock; /// Registers multiple routePatterns for one handler with default priority (0) in the receiving scheme namespace. - (void)addRoutes:(NSArray<NSString *> *)routePatterns handler:(BOOL (^__nullable)(NSDictionary<NSString *, id> *parameters))handlerBlock; /// Removes a routePattern from the receiving scheme namespace. - (void)removeRoute:(NSString *)routePattern; /// Removes all routes from the receiving scheme namespace. - (void)removeAllRoutes; /// Registers a routePattern with default priority (0) using dictionary-style subscripting. - (void)setObject:(nullable id)handlerBlock forKeyedSubscript:(NSString *)routePatten; #pragma mark - Routing URLs /// Returns whether a route will match a given URL in any routes scheme, but does not call any blocks. + (BOOL)canRouteURL:(nullable NSURL *)URL; /// Returns whether a route will match a given URL in a specific scheme, but does not call any blocks. - (BOOL)canRouteURL:(nullable NSURL *)URL; /// Routes a URL in any routes scheme, calling handler blocks for patterns that match the URL until one returns YES. /// If no matching route is found, the unmatchedURLHandler will be called (if set). + (BOOL)routeURL:(nullable NSURL *)URL; /// Routes a URL in a specific scheme, calling handler blocks for patterns that match the URL until one returns YES. /// If no matching route is found, the unmatchedURLHandler will be called (if set). - (BOOL)routeURL:(nullable NSURL *)URL; /// Routes a URL in any routes scheme, calling handler blocks (for patterns that match URL) until one returns YES. /// Additional parameters get passed through to the matched route block. + (BOOL)routeURL:(nullable NSURL *)URL withParameters:(nullable NSDictionary<NSString *, id> *)parameters; /// Routes a URL in a specific scheme, calling handler blocks (for patterns that match URL) until one returns YES. /// Additional parameters get passed through to the matched route block. - (BOOL)routeURL:(nullable NSURL *)URL withParameters:(nullable NSDictionary<NSString *, id> *)parameters; @end #pragma mark - Global Options @interface JLRoutes (GlobalOptions) /// Enable or disable verbose logging. Defaults to NO. + (void)setVerboseLoggingEnabled:(BOOL)loggingEnabled; /// Returns current verbose logging enabled state. + (BOOL)isVerboseLoggingEnabled; /// Tells JLRoutes that it should manually replace '+' in parsed values to ' '. Defaults to YES. + (void)setShouldDecodePlusSymbols:(BOOL)shouldDecode; /// Returns current plus symbol decoding state. + (BOOL)shouldDecodePlusSymbols; @end #pragma mark - Deprecated extern NSString *const kJLRoutePatternKey DEPRECATED_MSG_ATTRIBUTE("Use JLRoutePatternKey instead."); extern NSString *const kJLRouteURLKey DEPRECATED_MSG_ATTRIBUTE("Use JLRouteURLKey instead."); extern NSString *const kJLRouteSchemeKey DEPRECATED_MSG_ATTRIBUTE("Use JLRouteSchemeKey instead."); extern NSString *const kJLRouteWildcardComponentsKey DEPRECATED_MSG_ATTRIBUTE("Use JLRouteWildcardComponentsKey instead."); extern NSString *const kJLRoutesGlobalRoutesScheme DEPRECATED_MSG_ATTRIBUTE("Use JLRoutesGlobalRoutesScheme instead."); extern NSString *const kJLRouteNamespaceKey DEPRECATED_MSG_ATTRIBUTE("Use JLRouteSchemeKey instead."); extern NSString *const kJLRoutesGlobalNamespaceKey DEPRECATED_MSG_ATTRIBUTE("Use JLRoutesGlobalRoutesScheme instead."); @interface JLRoutes (Deprecated) // All the class method conveniences have been deprecated. They make the API/header confusing and are unncessary. // If you're using these, please switch to calling the matching instance method on +globalRoutes instead for the same behavior. + (void)addRoute:(NSString *)routePattern handler:(BOOL (^__nullable)(NSDictionary<NSString *, id> *parameters))handlerBlock DEPRECATED_MSG_ATTRIBUTE("Use the matching instance method on +globalRoutes instead."); + (void)addRoute:(NSString *)routePattern priority:(NSUInteger)priority handler:(BOOL (^__nullable)(NSDictionary<NSString *, id> *parameters))handlerBlock DEPRECATED_MSG_ATTRIBUTE("Use the matching instance method on +globalRoutes instead."); + (void)addRoutes:(NSArray<NSString *> *)routePatterns handler:(BOOL (^__nullable)(NSDictionary<NSString *, id> *parameters))handlerBlock DEPRECATED_MSG_ATTRIBUTE("Use the matching instance method on +globalRoutes instead."); + (void)removeRoute:(NSString *)routePattern DEPRECATED_MSG_ATTRIBUTE("Use the matching instance method on +globalRoutes instead."); + (void)removeAllRoutes DEPRECATED_MSG_ATTRIBUTE("Use the matching instance method on +globalRoutes instead."); + (BOOL)canRouteURL:(nullable NSURL *)URL withParameters:(nullable NSDictionary<NSString *, id> *)parameters DEPRECATED_MSG_ATTRIBUTE("Use +canRouteURL: instead."); // Other deprecations - (BOOL)canRouteURL:(nullable NSURL *)URL withParameters:(nullable NSDictionary<NSString *, id> *)parameters DEPRECATED_MSG_ATTRIBUTE("Use -canRouteURL: instead."); @end NS_ASSUME_NONNULL_END ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Router/JLRouters/Classes/JLRoutes.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
1,723
```objective-c // // YFCounterInteractor.h // BigShow1949 // // Created by big show on 2018/10/15. // #import <Foundation/Foundation.h> #import "YFCounterInteractorIO.h" @interface YFCounterInteractor : NSObject<YFCounterInteractorInput> @property (nonatomic, weak) id<YFCounterInteractorOutput> output; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Counter/YFCounterInteractor.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
86
```objective-c // // YFCounterPresenter.h // BigShow1949 // // Created by big show on 2018/10/15. // #import <Foundation/Foundation.h> #import "YFCounterInteractorIO.h" #import "YFCounterView.h" @interface YFCounterPresenter : NSObject<YFCounterInteractorOutput> @property (nonatomic, weak) id<YFCounterView> delegateView; @property (nonatomic, strong) id<YFCounterInteractorInput> delegateInteractor; // storngVC - (void)updateView; - (void)increment; - (void)decrement; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Counter/YFCounterPresenter.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
135
```objective-c // // YFCounterInteractor.m // BigShow1949 // // Created by big show on 2018/10/15. // #import "YFCounterInteractor.h" @interface YFCounterInteractor() @property (nonatomic, assign) NSUInteger count; @end @implementation YFCounterInteractor #pragma mark - YFCounterInteractorInput - (void)requestCount { [self sendCount]; } - (void)increment { ++self.count; [self sendCount]; } - (void)decrement { if ([self canDecrement]) { --self.count; [self sendCount]; } } - (BOOL)canDecrement { return (self.count > 0); } - (void)sendCount { [self.output updateCount:self.count]; } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Counter/YFCounterInteractor.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
178
```objective-c // // YFCounterView.h // BigShow1949 // // Created by big show on 2018/10/15. // @protocol YFCounterView <NSObject> - (void)setCountText:(NSString*)countText; - (void)setDecrementEnabled:(BOOL)enabled; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Counter/YFCounterView.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
68
```objective-c // // YFToDoBaseViewController.m // BigShow1949 // // Created by big show on 2018/12/7. // #import "YFToDoBaseViewController.h" // List #import "YFToDoWireframe.h" #import "YFToDoInteractor.h" #import "YFToDoPresenter.h" #import "YFToDoViewController.h" @interface YFToDoBaseViewController () @property (nonatomic, strong) YFToDoWireframe *wireframe; @property (nonatomic, strong) YFToDoViewController *viewController; @end @implementation YFToDoBaseViewController - (void)viewDidLoad { [super viewDidLoad]; [self configureDependencies]; self.view.backgroundColor = [UIColor whiteColor]; UIButton *redBtn = [[UIButton alloc] initWithFrame:CGRectMake(100, 100, 80, 44)]; [redBtn setTitle:@"Button" forState:UIControlStateNormal]; [redBtn addTarget:self action:@selector(buttonClick) forControlEvents:UIControlEventTouchUpInside]; redBtn.titleLabel.textColor = [UIColor blackColor]; redBtn.backgroundColor = [UIColor blueColor]; [self.view addSubview:redBtn]; } - (void)buttonClick { [self.wireframe pushViewController:self.viewController fromViewController:self]; } - (void)configureDependencies { YFToDoViewController *viewController = [[YFToDoViewController alloc] init]; YFToDoPresenter *presenter = [YFToDoPresenter new]; YFToDoWireframe *wireframe = [YFToDoWireframe new]; YFToDoInteractor *interactor = [YFToDoInteractor new]; presenter.wireframe = wireframe; presenter.interactor = interactor; // interactor presenter.interactoroutput presenter.viewController = viewController; interactor.output = presenter; wireframe.presenter = presenter; viewController.presenter = presenter; self.wireframe = wireframe; self.viewController = viewController; } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/ToDo/YFToDoBaseViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
468
```objective-c // // YFToDoWireframe.h // BigShow1949 // // Created by big show on 2018/12/8. // #import <Foundation/Foundation.h> @class YFToDoPresenter; @interface YFToDoWireframe : NSObject @property (nonatomic, strong) YFToDoPresenter *presenter; - (void)presentListInterfaceFromVC:(UIViewController *)vc; - (void)pushViewController:(UIViewController *)destination fromViewController:(UIViewController *)source; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/ToDo/List/Router/YFToDoWireframe.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
102
```objective-c // // YFToDoWireframe.m // BigShow1949 // // Created by big show on 2018/12/8. // #import "YFToDoWireframe.h" @implementation YFToDoWireframe - (void)pushViewController:(UIViewController *)destination fromViewController:(UIViewController *)source { [source.navigationController pushViewController:destination animated:YES]; } - (void)presentListInterfaceFromVC:(UIViewController *)vc { } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/ToDo/List/Router/YFToDoWireframe.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
96
```objective-c // // YFToDoBaseViewController.h // BigShow1949 // // Created by big show on 2018/12/7. // #import <UIKit/UIKit.h> @interface YFToDoBaseViewController : UIViewController @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/ToDo/YFToDoBaseViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
52
```objective-c // // YFToDoInteractor.m // BigShow1949 // // Created by big show on 2018/12/8. // #import "YFToDoInteractor.h" @implementation YFToDoInteractor #pragma mark - YFToDoInteractorInput - (void)findUpcomingItems { // [self.output foundUpcomingItems:@[@"1",@"2",@"3",@"4",]]; } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/ToDo/List/Interactor/YFToDoInteractor.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
95
```objective-c // // YFToDoInteractorInterface.h // BigShow1949 // // Created by big show on 2018/12/8. // #ifndef YFToDoInteractorInterface_h #define YFToDoInteractorInterface_h @protocol YFToDoInteractorInput - (void)findUpcomingItems; @end @protocol YFToDoInteractorOutput - (void)foundUpcomingItems:(NSArray *)upcomingItems; @end #endif /* YFToDoInteractorInterface_h */ ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/ToDo/List/Interactor/YFToDoInteractorInterface.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
108
```objective-c // // YFToDoInteractor.h // BigShow1949 // // Created by big show on 2018/12/8. // #import <Foundation/Foundation.h> #import "YFToDoInteractorInterface.h" @interface YFToDoInteractor : NSObject <YFToDoInteractorInput> @property (nonatomic, weak) id<YFToDoInteractorOutput> output; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/ToDo/List/Interactor/YFToDoInteractor.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
86
```objective-c // // YFToDoViewController.h // BigShow1949 // // Created by big show on 2018/12/8. // #import <UIKit/UIKit.h> #import "YFToDoPresenterInterface.h" #import "YFToDoViewControllerInterface.h" @interface YFToDoViewController : UITableViewController<YFToDoViewControllerDelegate> @property (nonatomic, weak) id<YFToDoPresenterDelegate> presenter; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/ToDo/List/View/YFToDoViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
90
```objective-c // // YFToDoViewControllerInterface.h // BigShow1949 // // Created by big show on 2018/12/8. // #ifndef YFToDoViewControllerInterface_h #define YFToDoViewControllerInterface_h @class VTDUpcomingDisplayData; @protocol YFToDoViewControllerDelegate - (void)showNoContentMessage; - (void)showUpcomingDisplayData:(VTDUpcomingDisplayData *)data; - (void)reloadEntries; @end #endif /* YFToDoViewControllerInterface_h */ ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/ToDo/List/View/YFToDoViewControllerInterface.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
112
```objective-c // // YFToDoViewController.m // BigShow1949 // // Created by big show on 2018/12/8. // #import "YFToDoViewController.h" @interface YFToDoViewController () @end @implementation YFToDoViewController - (void)viewDidLoad { [super viewDidLoad]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self.presenter updateView]; } #pragma mark - Table view data source - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 2; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 3; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"test"]; if (!cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewStylePlain reuseIdentifier:@"test"]; } cell.textLabel.text = [NSString stringWithFormat:@"row = %ld", (long)indexPath.row]; return cell; } #pragma mark - YFToDoViewControllerDelegate - (void)showNoContentMessage { } - (void)showUpcomingDisplayData:(VTDUpcomingDisplayData *)data { } - (void)reloadEntries { } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/ToDo/List/View/YFToDoViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
262
```objective-c // // YFToDoPresenterInterface.h // BigShow1949 // // Created by big show on 2018/12/8. // #ifndef YFToDoPresenterInterface_h #define YFToDoPresenterInterface_h @protocol YFToDoPresenterDelegate - (void)updateView; - (void)addNewEntry; @end #endif /* YFToDoPresenterInterface_h */ ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/ToDo/List/Presenter/YFToDoPresenterInterface.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
84
```objective-c // // YFToDoPresenter.h // BigShow1949 // // Created by big show on 2018/12/8. // #import <Foundation/Foundation.h> #import "YFToDoInteractorInterface.h" #import "YFToDoPresenterInterface.h" #import "YFToDoViewControllerInterface.h" @class YFToDoWireframe; @interface YFToDoPresenter : NSObject<YFToDoPresenterDelegate,YFToDoInteractorOutput> @property (nonatomic, strong) YFToDoWireframe *wireframe; @property (nonatomic, strong) id<YFToDoInteractorInput> interactor; @property (nonatomic, strong) UIViewController<YFToDoViewControllerDelegate> *viewController; //@property (nonatomic, strong) UIViewController<VTDListViewInterface> *userInterface; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/ToDo/List/Presenter/YFToDoPresenter.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
164
```objective-c // // YFToDoPresenter.m // BigShow1949 // // Created by big show on 2018/12/8. // #import "YFToDoPresenter.h" @implementation YFToDoPresenter #pragma mark - YFToDoPresenterDelegate - (void)updateView { NSLog(@"interactor ==== %p", self.interactor); [self.interactor findUpcomingItems]; } - (void)addNewEntry { } #pragma mark - YFToDoInteractorOutput - (void)foundUpcomingItems:(NSArray *)upcomingItems { if ([upcomingItems count] == 0) { [self.viewController showNoContentMessage]; } else { [self.viewController showUpcomingDisplayData:@[]]; } } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/ToDo/List/Presenter/YFToDoPresenter.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
168
```objective-c // // YFToDoItem.h // BigShow1949 // // Created by big show on 2018/12/8. // #import <Foundation/Foundation.h> @interface YFToDoItem : NSObject @property (nonatomic, readonly, copy) NSString* title; @property (nonatomic, readonly, copy) NSString* dueDay; + (instancetype)itemWithTitle:(NSString*)title dueDay:(NSString*)dueDay; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/ToDo/List/Enity/YFToDoItem.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
96
```objective-c // // YFToDoSection.h // BigShow1949 // // Created by big show on 2018/12/8. // #import <Foundation/Foundation.h> @interface YFToDoSection : NSObject @property (nonatomic, readonly, copy) NSString* name; @property (nonatomic, readonly, copy) NSString* imageName; @property (nonatomic, readonly, copy) NSArray* items; // array of VTDUpcomingDisplayItem + (instancetype)sectionWithName:(NSString *)name imageName:(NSString *)imageName items:(NSArray *)items; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/ToDo/List/Enity/YFToDoSection.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
123
```objective-c // // YFToDoItem.m // BigShow1949 // // Created by big show on 2018/12/8. // #import "YFToDoItem.h" @interface YFToDoItem() @property (nonatomic, copy) NSString*title; @property (nonatomic, copy) NSString*dueDay; @end @implementation YFToDoItem + (instancetype)itemWithTitle:(NSString*)title dueDay:(NSString*)dueDay { YFToDoItem *item = [[YFToDoItem alloc] init]; item.title = title; item.dueDay = dueDay; return item; } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/ToDo/List/Enity/YFToDoItem.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
133
```objective-c // // YFToDoData.h // BigShow1949 // // Created by big show on 2018/12/8. // #import <Foundation/Foundation.h> @interface YFToDoData : NSObject @property (nonatomic, readonly, copy,) NSArray* sections; + (instancetype)dataWithSections:(NSArray *)sections; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/ToDo/List/Enity/YFToDoData.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
74
```objective-c // // YFToDoSection.m // BigShow1949 // // Created by big show on 2018/12/8. // #import "YFToDoSection.h" @interface YFToDoSection() @property (nonatomic, copy) NSString* name; @property (nonatomic, copy) NSString* imageName; @property (nonatomic, copy) NSArray* items; @end @implementation YFToDoSection + (instancetype)sectionWithName:(NSString *)name imageName:(NSString *)imageName items:(NSArray *)items { YFToDoSection *section = [[YFToDoSection alloc] init]; section.name = name; section.imageName = imageName; section.items = items; return section; } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/ToDo/List/Enity/YFToDoSection.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
154
```objective-c // // YFToDoData.m // BigShow1949 // // Created by big show on 2018/12/8. // #import "YFToDoData.h" @interface YFToDoData () @property (nonatomic, copy) NSArray* sections; @end @implementation YFToDoData + (instancetype)dataWithSections:(NSArray *)sections { YFToDoData* data = [[YFToDoData alloc] init]; data.sections = sections; return data; } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/ToDo/List/Enity/YFToDoData.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
108
```objective-c // // YFLoginViperViewController.h // BigShow1949 // // Created by big show on 2018/10/16. // #import <UIKit/UIKit.h> @interface YFNoteListViperViewController : UIViewController @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/YFNoteListViperViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
55
```objective-c // // YFLoginViperViewController.m // BigShow1949 // // Created by big show on 2018/10/16. // #import "YFNoteListViperViewController.h" #import "YFTNoteListModuleBuilder.h" #import "YFNoteListViewController.h" #import "YFNoteDataManager.h" #import "YFRouter.h" #import "YFNoteListRouter.h" @interface YFNoteListViperViewController () @end @implementation YFNoteListViperViewController - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor whiteColor]; /* zuikpath_to_url */ } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; UIButton *redBtn = [[UIButton alloc] initWithFrame:CGRectMake(100, 100, 80, 44)]; [redBtn setTitle:@"Button" forState:UIControlStateNormal]; [redBtn addTarget:self action:@selector(buttonClick) forControlEvents:UIControlEventTouchUpInside]; redBtn.titleLabel.textColor = [UIColor blackColor]; redBtn.backgroundColor = [UIColor blueColor]; [self.view addSubview:redBtn]; } - (void)buttonClick { YFNoteListViewController<YFViperViewPrivate> *noteListVC = [[YFNoteListViewController alloc] init]; id<YFNoteListRouter>router = (id)[[YFRouter alloc] init]; [YFTNoteListModuleBuilder buildView:noteListVC noteListDataService:[YFNoteDataManager sharedInsatnce] router:router]; [self.navigationController pushViewController:noteListVC animated:YES]; } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/YFNoteListViperViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
341
```objective-c // // YFNoteDataManager.h // BigShow1949 // // Created by big show on 2018/10/16. // #import <Foundation/Foundation.h> #import "YFNoteListDataService.h" @class YFNoteModel; @interface YFNoteDataManager : NSObject<YFNoteListDataService> @property (nonatomic, readonly, strong) NSArray<YFNoteModel *> *noteList; + (instancetype)sharedInsatnce; - (void)fetchAllNotesWithCompletion:(void(^)(NSArray *notes))completion; - (void)storeNote:(YFNoteModel *)note; - (void)deleteNote:(YFNoteModel *)noteToDelete; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/NoteService/YFNoteDataManager.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
145
```objective-c // // YFEditorInteractorEventHandler.h // BigShow1949 // // Created by big show on 2018/12/9. // #ifndef YFEditorInteractorEventHandler_h #define YFEditorInteractorEventHandler_h #endif /* YFEditorInteractorEventHandler_h */ ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/EditorModule/Interactor/YFEditorInteractorEventHandler.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
64
```objective-c // // YFEditorInteractorInput.h // BigShow1949 // // Created by big show on 2018/12/9. // #ifndef YFEditorInteractorInput_h #define YFEditorInteractorInput_h @class YFNoteModel; @protocol YFEditorInteractorInput <NSObject> - (nullable YFNoteModel *)currentEditingNote; - (void)storeCurrentEditingNote; - (nullable NSString *)currentEditingNoteTitle; - (nullable NSString *)currentEditingNoteContent; @end #endif /* YFEditorInteractorInput_h */ ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/EditorModule/Interactor/YFEditorInteractorInput.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
123
```objective-c // // YFEditorInteractor.m // BigShow1949 // // Created by big show on 2018/12/9. // #import "YFEditorInteractor.h" #import "YFNoteModel.h" #import "YFNoteDataManager.h" #import "YFEditorInteractorDataSource.h" @interface YFEditorInteractor() @property (nonatomic, strong, nullable) YFNoteModel *currentEditingNote; @end @implementation YFEditorInteractor - (instancetype)initWithEditingNote:(nullable YFNoteModel*)note { if (self = [super init]) { if (note) { _currentEditingNote = note; } } return self; } @synthesize dataSource; @synthesize eventHandler; #pragma mark - YFEditorInteractorInput - (nullable YFNoteModel *)currentEditingNote { NSLog(@"dataSource = %@", self.dataSource); NSString *title = [self.dataSource currentEditingNoteTitle]; NSString *content = [self.dataSource currentEditingNoteContent]; if (!title && !content) { return nil; } if (!_currentEditingNote) { _currentEditingNote = [[YFNoteModel alloc] initWithNewNoteForTitle:title content:content]; } else { _currentEditingNote = [[YFNoteModel alloc] initWithUUID:_currentEditingNote.uuid title:title content:content]; } return _currentEditingNote; } - (void)storeCurrentEditingNote { if (self.currentEditingNote.title.length == 0) { return; } [[YFNoteDataManager sharedInsatnce] storeNote:self.currentEditingNote]; } - (nullable NSString *)currentEditingNoteTitle { return _currentEditingNote.title; } - (nullable NSString *)currentEditingNoteContent { return _currentEditingNote.content; } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/EditorModule/Interactor/YFEditorInteractor.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
388
```objective-c // // YFEditorInteractor.h // BigShow1949 // // Created by big show on 2018/12/9. // #import <Foundation/Foundation.h> #import "YFViperInteractor.h" #import "YFEditorInteractorInput.h" @class YFNoteModel; @protocol YFEditorInteractorDataSource; @protocol YFEditorInteractorEventHandler; @interface YFEditorInteractor : NSObject<YFViperInteractor,YFEditorInteractorInput> @property (nonatomic, weak) id<YFEditorInteractorDataSource> dataSource; @property (nonatomic, weak) id<YFEditorInteractorEventHandler> eventHandler; - (instancetype)initWithEditingNote:(nullable YFNoteModel *)note; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/EditorModule/Interactor/YFEditorInteractor.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
157
```objective-c // // YFEditorInteractorDataSource.h // BigShow1949 // // Created by big show on 2018/12/9. // #ifndef YFEditorInteractorDataSource_h #define YFEditorInteractorDataSource_h @protocol YFEditorInteractorDataSource <NSObject> - (nullable NSString *)currentEditingNoteTitle; - (nullable NSString *)currentEditingNoteContent; @end #endif /* YFEditorInteractorDataSource_h */ ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/EditorModule/Interactor/YFEditorInteractorDataSource.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
96
```objective-c // // YFEditorViewViewProtocol.h // BigShow1949 // // Created by big show on 2018/12/9. // #ifndef YFEditorViewProtocol_h #define YFEditorViewProtocol_h typedef NS_ENUM(NSInteger,YFEditorMode) { YFEditorModeCreate, YFEditorModeModify }; @protocol YFEditorDelegate; @protocol YFEditorViewProtocol @property (nonatomic, weak) id<YFEditorDelegate> delegate; @property (nonatomic, assign) YFEditorMode editMode; - (nullable NSString *)titleString; - (nullable NSString *)contentString; - (void)updateTitleString:(NSString *)title; - (void)updateContentString:(NSString *)content; @end #endif /* YFEditorViewViewProtocol_h */ ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/EditorModule/View/YFEditorViewProtocol.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
171
```objective-c // // YFEditorViewEventHandler.h // BigShow1949 // // Created by big show on 2018/12/9. // #ifndef YFEditorViewEventHandler_h #define YFEditorViewEventHandler_h #import "YFViperViewEventHandler.h" @protocol YFViperRouter; @protocol YFEditorViewEventHandler<YFViperViewEventHandler> - (void)didTouchNavigationBarDoneButton; - (id<YFViperRouter>)router; @end #endif /* YFEditorViewEventHandler_h */ ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/EditorModule/View/YFEditorViewEventHandler.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
114
```objective-c // // YFEditorViewController.h // BigShow1949 // // Created by big show on 2018/12/9. // #import <UIKit/UIKit.h> #import "YFEditorViewProtocol.h" #import "YFViperView.h" @protocol YFEditorDelegate; @interface YFEditorViewController : UIViewController<YFViperView,YFEditorViewProtocol> @property (nonatomic, weak) id<YFEditorDelegate> delegate; @property (nonatomic, assign) YFEditorMode editMode; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/EditorModule/View/YFEditorViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
113
```objective-c // // YFNoteDataManager.m // BigShow1949 // // Created by big show on 2018/10/16. // #import "YFNoteDataManager.h" #import "YFNoteModel.h" @interface YFNoteDataManager() @property (nonatomic, strong) NSMutableArray<NSString *> *noteUUIDs; @property (nonatomic, strong) NSMutableArray<YFNoteModel *> *notes; @end @implementation YFNoteDataManager #pragma mark - Public - (NSArray<YFNoteModel *> *)noteList { return [self.notes copy]; } + (instancetype)sharedInsatnce { static YFNoteDataManager *shared; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ shared = [[YFNoteDataManager alloc] init]; }); return shared; } - (void)fetchAllNotesWithCompletion:(void(^)(NSArray *notes))completion { NSAssert([NSThread isMainThread], @"main thread only, otherwise use lock to make thread safety."); NSArray *noteList = self.noteList; if (!noteList) { self.noteUUIDs = [NSMutableArray array]; self.notes = [NSMutableArray array]; NSArray<NSString *> *uuids = [self noteListUUIDArray]; NSMutableArray *notes = [NSMutableArray array]; for (NSString *uuid in uuids) { YFNoteModel *note = [self localStoredNoteWithUUID:uuid]; if (note) { [notes addObject:note]; } } [self.noteUUIDs addObjectsFromArray:uuids]; [self.notes addObjectsFromArray:notes]; noteList = notes; } if (completion) { completion(noteList); } } - (void)storeNote:(YFNoteModel *)note { NSString *filePath = [YFNoteDataManager _o_pathForLocalStoredNoteWithUUID:note.uuid]; BOOL success = [NSKeyedArchiver archiveRootObject:note toFile:filePath]; NSAssert(success == YES, nil); if (success) { if (![self.noteUUIDs containsObject:note.uuid]) { [self.noteUUIDs addObject:note.uuid]; [self.notes addObject:note]; [self storeNoteListUUIDs]; } else { NSUInteger idx; for (idx = 0; idx < self.notes.count; idx++) { YFNoteModel *noteTemp = [self.notes objectAtIndex:idx]; if ([noteTemp.uuid isEqualToString:note.uuid]) { NSLog(@"idx = %lu", (unsigned long)idx); break; } } // idx0 [self.notes replaceObjectAtIndex:idx withObject:note]; } } } - (void)deleteNote:(YFNoteModel *)noteToDelete { NSParameterAssert(noteToDelete.uuid); if (![self.noteUUIDs containsObject:noteToDelete.uuid]) { NSAssert(NO, @"note to delete not exists"); return; } [self.noteUUIDs removeObject:noteToDelete.uuid]; [self storeNoteListUUIDs]; YFNoteModel *noteToDeleteInArray; for (YFNoteModel *note in self.notes) { if ([note.uuid isEqualToString:noteToDelete.uuid]) { noteToDeleteInArray = note; break; } } NSAssert(noteToDeleteInArray != nil, @"didn't find note to delete in notes array"); [self.notes removeObject:noteToDeleteInArray]; NSString *filePath = [YFNoteDataManager _o_pathForLocalStoredNoteWithUUID:noteToDelete.uuid]; NSError *error; [[NSFileManager defaultManager] removeItemAtPath:filePath error:&error]; NSAssert(error == nil, nil); } #pragma mark - Private - (void)storeNoteListUUIDs { NSAssert([NSThread isMainThread], @"main thread only, otherwise use lock to make thread safety."); NSString *filePath = [YFNoteDataManager _o_pathForNoteListUUIDsFile]; BOOL success = [NSKeyedArchiver archiveRootObject:self.noteUUIDs toFile:filePath]; NSAssert(success == YES, nil); } - (YFNoteModel *)localStoredNoteWithUUID:(NSString *)uuid { NSParameterAssert(uuid); NSAssert([NSThread isMainThread], @"main thread only, otherwise use lock to make thread safety."); YFNoteModel *note = [NSKeyedUnarchiver unarchiveObjectWithFile:[YFNoteDataManager _o_pathForLocalStoredNoteWithUUID:uuid]]; return note; } - (NSArray<NSString *> *)noteListUUIDArray { NSAssert([NSThread isMainThread], @"main thread only, otherwise use lock to make thread safety."); NSArray * noteListUUIDs = [NSKeyedUnarchiver unarchiveObjectWithFile:[YFNoteDataManager _o_pathForNoteListUUIDsFile]]; if (!noteListUUIDs) { return @[]; } return noteListUUIDs; } + (NSString *)_o_pathForLocalStoredNoteWithUUID:(NSString *)uuid { NSParameterAssert(uuid); return [[self _o_pathForLocalStoreNote] stringByAppendingPathComponent:uuid]; } + (NSString *)_o_pathForNoteListUUIDsFile { NSString *document = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]; return [document stringByAppendingPathComponent:@"noteUUIDs"]; } + (NSString *)_o_pathForLocalStoreNote { NSString *document = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]; NSString *path = [document stringByAppendingPathComponent:@"Notes"]; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ NSError *error; [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&error]; NSAssert(error == nil, nil); }); return path; } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/NoteService/YFNoteDataManager.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
1,264
```objective-c // // YFEditorViewDataSource.h // BigShow1949 // // Created by big show on 2018/12/9. // #ifndef YFEditorViewDataSource_h #define YFEditorViewDataSource_h @protocol YFEditorViewDataSource @end #endif /* YFEditorViewDataSource_h */ ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/EditorModule/View/YFEditorViewDataSource.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
69
```objective-c // // YFEditorViewController.m // BigShow1949 // // Created by big show on 2018/12/9. // #import "YFEditorViewController.h" #import "YFEditorViewDataSource.h" #import "YFEditorViewEventHandler.h" @interface YFEditorViewController () @property (nonatomic, strong) id<YFEditorViewEventHandler> eventHandler; @property (nonatomic, strong) id<YFEditorViewDataSource> viewDataSource; @property (nonatomic, strong) UITextField *titleTextField; @end @implementation YFEditorViewController - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor whiteColor]; [self setupNav]; [self setupUI]; // respondsToSelector // if ([self.eventHandler respondsToSelector:@selector(handleViewReady)]) { // [self.eventHandler handleViewReady]; // } [self.eventHandler handleViewReady]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; // if ([self.eventHandler respondsToSelector:@selector(handleViewWillAppear:)]) { // [self.eventHandler handleViewWillAppear:animated]; // } [self.eventHandler handleViewWillAppear:animated]; } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [self.eventHandler handleViewDidAppear:animated]; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [self.eventHandler handleViewWillDisappear:animated]; } #pragma mark - YFEditorViewProtocol - (nullable NSString *)titleString { return self.titleTextField.text; } - (nullable NSString *)contentString { return @""; } - (void)updateTitleString:(NSString *)title { self.titleTextField.text = title; } - (void)updateContentString:(NSString *)content {} #pragma mark - Private - (void)setupNav { self.title = @"Editor"; UIBarButtonItem *addNoteItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self.eventHandler action:@selector(didTouchNavigationBarDoneButton)]; self.navigationItem.rightBarButtonItem = addNoteItem; // if ([self.eventHandler respondsToSelector:@selector(handleViewReady)]) { // [self.eventHandler handleViewReady]; // } } - (void)setupUI { self.titleTextField = [[UITextField alloc] initWithFrame:CGRectMake(100, 100, 200, 40)]; self.titleTextField.placeholder = @""; self.titleTextField.layer.borderWidth = 1; self.titleTextField.layer.borderColor = [UIColor lightGrayColor].CGColor; [self.view addSubview:self.titleTextField]; } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/EditorModule/View/YFEditorViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
543
```objective-c // // YFEditorDelegate.h // BigShow1949 // // Created by big show on 2018/12/9. // #ifndef YFEditorDelegate_h #define YFEditorDelegate_h @class YFNoteModel; @protocol YFEditorDelegate <NSObject> - (void)editor:(UIViewController *)editor didFinishEditNote:(YFNoteModel *)note; @end #endif /* YFEditorDelegate_h */ ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/EditorModule/View/YFEditorDelegate.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
92
```objective-c // // YFEditorViewPresenter.h // BigShow1949 // // Created by big show on 2018/12/9. // #import <Foundation/Foundation.h> #import "YFViperPresenter.h" #import "YFEditorViewEventHandler.h" @interface YFEditorViewPresenter : NSObject<YFViperPresenter,YFEditorViewEventHandler> @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/EditorModule/Presenter/YFEditorViewPresenter.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
81
```objective-c // // YFEditorWireframe.h // BigShow1949 // // Created by big show on 2018/12/9. // #import <Foundation/Foundation.h> #import "YFViperWireframePrivate.h" @interface YFEditorWireframe : NSObject<YFViperWireframePrivate> @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/EditorModule/Wireframe/YFEditorWireframe.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
71
```objective-c // // YFEditorWireframeInput.h // BigShow1949 // // Created by big show on 2018/12/9. // #ifndef YFEditorWireframeInput_h #define YFEditorWireframeInput_h @protocol YFViperRouter; @protocol YFEditorWireframeInput <NSObject> - (id<YFViperRouter>)router; @end #endif /* YFEditorWireframeInput_h */ ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/EditorModule/Wireframe/YFEditorWireframeInput.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
95
```objective-c // // YFEditorViewPresenter.m // BigShow1949 // // Created by big show on 2018/12/9. // #import "YFEditorViewPresenter.h" #import "YFEditorWireframeInput.h" #import "YFViperView.h" #import "YFViperInteractor.h" #import "YFEditorViewProtocol.h" #import "YFEditorInteractorInput.h" #import "YFEditorDelegate.h" @interface YFEditorViewPresenter() @property (nonatomic, strong) id<YFEditorWireframeInput> wireframe; @property (nonatomic, weak) id<YFViperView,YFEditorViewProtocol> view; @property (nonatomic, strong) id<YFViperInteractor,YFEditorInteractorInput> interactor; @end @implementation YFEditorViewPresenter #pragma mark - YFViperViewEventHandler - (void)handleViewReady { if (self.view.editMode == YFEditorModeModify) { [self.view updateTitleString:[self.interactor currentEditingNoteTitle]]; [self.view updateContentString:[self.interactor currentEditingNoteContent]]; } } - (void)handleViewRemoved {} - (void)handleViewWillAppear:(BOOL)animated {} - (void)handleViewDidAppear:(BOOL)animated {} - (void)handleViewWillDisappear:(BOOL)animated {} - (void)handleViewDidDisappear:(BOOL)animated {} #pragma mark - YFEditorViewEventHandler - (void)didTouchNavigationBarDoneButton { // [self.interactor storeCurrentEditingNote]; // id<YFEditorDelegate> delegate = self.view.delegate; NSLog(@"[delegate class] = %@", [delegate class]); // YFNoteListViewPresenter if ([delegate respondsToSelector:@selector(editor:didFinishEditNote:)]) { [delegate editor:(UIViewController *)self.view didFinishEditNote:[self.interactor currentEditingNote]]; } } - (id<YFViperRouter>)router { return self.wireframe.router; } #pragma mark - YFEditorInteractorDataSource - (nullable NSString *)currentEditingNoteTitle { return [self.view titleString]; } - (nullable NSString *)currentEditingNoteContent { return [self.view contentString]; } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/EditorModule/Presenter/YFEditorViewPresenter.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
478
```objective-c // // YFEditorBuilder.m // BigShow1949 // // Created by big show on 2018/12/9. // #import "YFEditorBuilder.h" #import "YFEditorViewController.h" #import "YFEditorViewPresenter.h" #import "YFEditorInteractor.h" #import "YFEditorWireframe.h" #import "YFViperViewPrivate.h" #import "YFViperInteractorPrivate.h" #import "YFViperPresenterPrivate.h" #import "YFNoteModel.h" #import "YFViperPresenterPrivate.h" #import "NSObject+YFViperAssembly.h" @implementation YFEditorBuilder + (UIViewController *)viewForCreatingNoteWithDelegate:(id<YFEditorDelegate>)delegate router:(id<YFViperRouter>)router { YFEditorViewController *view = [[YFEditorViewController alloc] init]; view.delegate = delegate; view.editMode = YFEditorModeCreate; [self buildView:(id<YFViperViewPrivate>)view note:nil router:router]; return view; } + (UIViewController *)viewForEditingNoteWithUUID:(NSString *)uuid title:(NSString *)title content:(NSString *)content delegate:(id<YFEditorDelegate>)delegate router:(id<YFViperRouter>)router { YFEditorViewController *view = [[YFEditorViewController alloc] init]; view.delegate = delegate; view.editMode = YFEditorModeModify; YFNoteModel *note = [[YFNoteModel alloc] initWithUUID:uuid title:title content:content]; [self buildView:view note:note router:router]; return view; } + (void)buildView:(id<YFViperViewPrivate>)view note:(nullable YFNoteModel *)note router:(id<YFViperRouter>)router { // YFEditorViewPresenter *presenter = [[YFEditorViewPresenter alloc] init]; id<YFViperPresenterPrivate>presenter = (id)[[YFEditorViewPresenter alloc] init]; YFEditorInteractor *interactor = [[YFEditorInteractor alloc] initWithEditingNote:note]; id<YFViperWireframePrivate> wireframe = (id)[[YFEditorWireframe alloc] init]; // [self assembleViperForView:view presenter:(id<YFViperPresenterPrivate>)presenter interactor:(id<YFViperInteractorPrivate>)interactor wireframe:(id<YFViperWireframePrivate>)wireframe router:(id<YFViperRouter>)router]; // interactor.eventHandler = presenter; // interactor.dataSource = presenter; // // wireframe.view = view; // wireframe.router = router; // // [presenter setInteractor:interactor]; // [presenter setView:view]; // [presenter setWireframe:wireframe]; // // view.eventHandler = presenter; } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/EditorModule/Builder/YFEditorBuilder.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
655
```objective-c // // YFEditorWireframe.m // BigShow1949 // // Created by big show on 2018/12/9. // #import "YFEditorWireframe.h" #import "YFViperView.h" #import "YFViperRouter.h" @interface YFEditorWireframe() @property (nonatomic, weak) id<YFViperView> view; @property (nonatomic, strong) id<YFViperRouter> router; @end @implementation YFEditorWireframe @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/EditorModule/Wireframe/YFEditorWireframe.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
112
```objective-c // // YFRouter+YFLogin.m // BigShow1949 // // Created by big show on 2018/12/11. // #import "YFRouter+YFLogin.h" #import "YFLoginBuilder.h" @implementation YFRouter (YFLogin) + (UIViewController *)loginViewWithMessage:(NSString *)message delegate:(id<YFLoginViewDelegate>)delegate { return [YFLoginBuilder viewWithMessage:message delegate:delegate router:[self new]]; } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/Router/YFRouter+YFLogin.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
111
```objective-c // // YFRouter+YFLogin.h // BigShow1949 // // Created by big show on 2018/12/11. // #import "YFRouter.h" @protocol YFLoginViewDelegate; @interface YFRouter (YFLogin) + (UIViewController *)loginViewWithMessage:(NSString *)message delegate:(id<YFLoginViewDelegate>)delegate; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/Router/YFRouter+YFLogin.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
86
```objective-c // // YFRouter.m // BigShow1949 // // Created by big show on 2018/10/16. // #import "YFRouter.h" @implementation YFRouter + (void)pushViewController:(UIViewController *)destination fromViewController:(UIViewController *)source animated:(BOOL)animated { NSParameterAssert([destination isKindOfClass:[UIViewController class]]); NSParameterAssert(source.navigationController); [source.navigationController pushViewController:destination animated:animated]; } + (void)popViewController:(UIViewController *)viewController animated:(BOOL)animated { NSParameterAssert(viewController.navigationController); [viewController.navigationController popViewControllerAnimated:animated]; } + (void)presentViewController:(UIViewController *)viewControllerToPresent fromViewController:(UIViewController *)source animated:(BOOL)animated completion:(void (^ __nullable)(void))completion { NSParameterAssert(viewControllerToPresent); NSParameterAssert(source); [source presentViewController:viewControllerToPresent animated:animated completion:completion]; } + (void)dismissViewController:(UIViewController *)viewController animated:(BOOL)animated completion:(void (^ __nullable)(void))completion { NSParameterAssert(viewController); [viewController dismissViewControllerAnimated:animated completion:completion]; } + (UIViewController *)loginViewWithMessage:(NSString *)message delegate:(id<YFLoginViewDelegate>)delegate { return nil; } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/Router/YFRouter.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
264
```objective-c // // YFRouter+YFEditor.h // BigShow1949 // // Created by big show on 2018/12/9. // #import "YFRouter.h" @protocol YFEditorDelegate; @interface YFRouter (YFEditor) + (UIViewController *)viewForCreatingNoteWithDelegate:(id<YFEditorDelegate>)delegate; + (UIViewController *)viewForEditingNoteWithUUID:(NSString *)uuid title:(NSString *)title content:(NSString *)content delegate:(id<YFEditorDelegate>)delegate; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/Router/YFRouter+YFEditor.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
116
```objective-c // // YFRouter.h // BigShow1949 // // Created by big show on 2018/10/16. // #import <Foundation/Foundation.h> @protocol YFLoginViewDelegate; @interface YFRouter : NSObject + (void)pushViewController:(UIViewController *)destination fromViewController:(UIViewController *)source animated:(BOOL)animated; + (void)popViewController:(UIViewController *)viewController animated:(BOOL)animated; + (void)presentViewController:(UIViewController *)viewControllerToPresent fromViewController:(UIViewController *)source animated:(BOOL)animated completion:(void (^ __nullable)(void))completion; + (void)dismissViewController:(UIViewController *)viewController animated:(BOOL)animated completion:(void (^ __nullable)(void))completion; // + (UIViewController *)loginViewWithMessage:(NSString *)message delegate:(id<YFLoginViewDelegate>)delegate ; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/Router/YFRouter.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
174
```objective-c // // YFEditorBuilder.h // BigShow1949 // // Created by big show on 2018/12/9. // #import <Foundation/Foundation.h> @protocol YFEditorDelegate,YFViperRouter; @interface YFEditorBuilder : NSObject + (UIViewController *)viewForCreatingNoteWithDelegate:(id<YFEditorDelegate>)delegate router:(id<YFViperRouter>)router; + (UIViewController *)viewForEditingNoteWithUUID:(NSString *)uuid title:(NSString *)title content:(NSString *)content delegate:(id<YFEditorDelegate>)delegate router:(id<YFViperRouter>)router; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/EditorModule/Builder/YFEditorBuilder.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
138
```objective-c // // YFViper.m // BigShow1949 // // Created by big show on 2018/10/17. // #import <Foundation/Foundation.h> ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/Protocol/YFViper.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
40
```objective-c // // YFViperInteractorPrivate.m // BigShow1949 // // Created by big show on 2018/10/17. // #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> @protocol YFViperInteractorPrivate<YFViperInteractor> - (void)setEventHandler:(id)eventHandler; - (void)setDataSource:(id)dataSource; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/Protocol/YFViperInteractorPrivate.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
88