Skip to content

Commit

Permalink
Merge pull request #13 from Cee/master
Browse files Browse the repository at this point in the history
Update Coding Style
  • Loading branch information
lightory committed Apr 30, 2015
2 parents 182a863 + 0178d1f commit f1e0774
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions HHRouter/HHRouter.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,27 @@
#import <objc/runtime.h>

@interface HHRouter ()
@property (strong, nonatomic) NSMutableDictionary* routes;
@property (strong, nonatomic) NSMutableDictionary *routes;
@end

@implementation HHRouter

+ (instancetype)shared
{
static HHRouter* router = nil;
static HHRouter *router = nil;
static dispatch_once_t onceToken;

dispatch_once(&onceToken, ^{
if (!router) {
router = [[self alloc] init];
}
if (!router) {
router = [[self alloc] init];
}
});
return router;
}

- (void)map:(NSString*)route toBlock:(HHRouterBlock)block
- (void)map:(NSString *)route toBlock:(HHRouterBlock)block
{
NSMutableDictionary* subRoutes = [self subRoutesToRoute:route];
NSMutableDictionary *subRoutes = [self subRoutesToRoute:route];

subRoutes[@"_"] = [block copy];
}
Expand All @@ -63,7 +63,7 @@ - (UIViewController *)matchController:(NSString *)route
return viewController;
}

- (UIViewController*)match:(NSString*)route
- (UIViewController *)match:(NSString *)route
{
return [self matchController:route];
}
Expand All @@ -72,7 +72,7 @@ - (HHRouterBlock)matchBlock:(NSString *)route
{
NSDictionary *params = [self paramsInRoute:route];
HHRouterBlock routerBlock = [params[@"block"] copy];
HHRouterBlock returnBlock = ^id(NSDictionary* aParams) {
HHRouterBlock returnBlock = ^id(NSDictionary *aParams) {
if (routerBlock) {
NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:params];
[dic addEntriesFromDictionary:aParams];
Expand All @@ -86,7 +86,7 @@ - (HHRouterBlock)matchBlock:(NSString *)route

- (id)callBlock:(NSString *)route
{
NSDictionary* params = [self paramsInRoute:route];
NSDictionary *params = [self paramsInRoute:route];
HHRouterBlock routerBlock = [params[@"block"] copy];

if (routerBlock) {
Expand All @@ -98,13 +98,12 @@ - (id)callBlock:(NSString *)route
// extract params in a route
- (NSDictionary *)paramsInRoute:(NSString *)route
{
NSMutableDictionary* params = [NSMutableDictionary dictionary];
NSMutableDictionary *params = [NSMutableDictionary dictionary];

params[@"route"] = [self stringFromFilterAppUrlScheme:route];

NSMutableDictionary *subRoutes = self.routes;
NSArray *pathComponents =
[self pathComponentsFromRoute:[self stringFromFilterAppUrlScheme:route]];
NSArray *pathComponents = [self pathComponentsFromRoute:[self stringFromFilterAppUrlScheme:route]];
for (NSString *pathComponent in pathComponents) {
BOOL found = NO;
NSArray *subRoutesKeys = subRoutes.allKeys;
Expand All @@ -128,13 +127,13 @@ - (NSDictionary *)paramsInRoute:(NSString *)route
// Extract Params From Query.
NSRange firstRange = [route rangeOfString:@"?"];
if (firstRange.location != NSNotFound && route.length > firstRange.location + firstRange.length) {
NSString* paramsString = [route substringFromIndex:firstRange.location + firstRange.length];
NSArray* paramStringArr = [paramsString componentsSeparatedByString:@"&"];
NSString *paramsString = [route substringFromIndex:firstRange.location + firstRange.length];
NSArray *paramStringArr = [paramsString componentsSeparatedByString:@"&"];
for (NSString *paramString in paramStringArr) {
NSArray *paramArr = [paramString componentsSeparatedByString:@"="];
if (paramArr.count > 1) {
NSString* key = [paramArr objectAtIndex:0];
NSString* value = [paramArr objectAtIndex:1];
NSString *key = [paramArr objectAtIndex:0];
NSString *value = [paramArr objectAtIndex:1];
params[key] = value;
}
}
Expand Down Expand Up @@ -241,8 +240,7 @@ @implementation UIViewController (HHRouter)

- (void)setParams:(NSDictionary *)paramsDictionary
{
objc_setAssociatedObject(self, &kAssociatedParamsObjectKey, paramsDictionary,
OBJC_ASSOCIATION_RETAIN_NONATOMIC);
objc_setAssociatedObject(self, &kAssociatedParamsObjectKey, paramsDictionary, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

- (NSDictionary *)params
Expand Down

0 comments on commit f1e0774

Please sign in to comment.